Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing utilities should be available to plugins #580

Closed
simonw opened this issue Oct 3, 2019 · 5 comments
Closed

Testing utilities should be available to plugins #580

simonw opened this issue Oct 3, 2019 · 5 comments

Comments

@simonw
Copy link
Owner

simonw commented Oct 3, 2019

I'm trying to write a plugin at the moment (datasette-atom) which needs to run unit tests against a full in-memory Datasette instance, in the same way that the Datasette test suite itself works.

I got it working by creating copies of the TestClient and TestResponse classes within the plugin itself:

simonw/datasette-atom@c0e3bd9#diff-33337525d2d877f7cc7f33737bfd2d7b

I had to do this because those classes are in the tests/ directory within Datasette, so they don't get included in the package that ships to PyPI.

It would be better if these classes were included in the main package in a way that made it easy for plugins to reuse them to write their own tests.

@simonw
Copy link
Owner Author

simonw commented Nov 14, 2019

I needed this again today for datasette-template-sql.

@simonw
Copy link
Owner Author

simonw commented Nov 14, 2019

One thing that would be useful is a way of constructing a Datasette() instance (and accompanying TestClient) which is attached to an in-memory database that the test itself can manipulate. This would make it trivial to run tests against hypothetical database tables - those tables could be created using sqlite-utils directly against the in-memory database that's being manipulated by the system-under-test.

@simonw
Copy link
Owner Author

simonw commented Nov 15, 2019

Here's where I copied the testing utilities into datasette-template-sql - very slightly modified from the utilities in datasette-atom: https://github.com/simonw/datasette-template-sql/blob/0ef0c7304bb5e658723e229d3ee463b9a76058f9/tests/utils.py

@simonw
Copy link
Owner Author

simonw commented Dec 4, 2019

@simonw
Copy link
Owner Author

simonw commented Feb 28, 2020

I don't think this is needed any more - I've found a really nice pattern for testing plugins using httpx instead, e.g. https://github.com/simonw/datasette-mask-columns/blob/f6f08ce21bdfc2731a02c42e1c9e25b4df769292/tests/test_mask_columns.py

@simonw simonw closed this as completed Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant