Extension of assertNumQueries that can record queries that were executed and show the differences in future runs.
Project description
Extension of assertNumQueries that can record queries that were executed and show the differences in future runs.
Documentation
The full documentation is at https://dj-test-queries.readthedocs.io.
Quickstart
Install dj-test-queries:
pip install dj-test-queries
Apply NumQueriesMixin to your test and use assertNumQueries as you would normally do:
from test_queries import NumQueriesMixin
class XYZTests(NumQueriesMixin, TestCase):
def test_xyz(self):
with self.assertNumQueries(3):
xyz()
Generating SQL log records
Run the tests with TEST_QUERIES_REWRITE_SQLLOGS environment variable to generate sqllog files:
TEST_QUERIES_REWRITE_SQLLOGS="true" manage.py test
Files like test_views.XYZTests.test_xyz.sqllog will appear in sqllog directory next to your test_views.py file.
If you will run the test next time and the queries will differ from previous, the test will print out output detailing the change with stacktrace from where the query was executed. You can also enlist the *.sqllog files to your repository to see the changes.
If the tests are executed without the TEST_QUERIES_REWRITE_SQLLOGS environment variable, the logs are created to files named like test_views.XYZTests.test_xyz.sqllog to make possible to compare the difference.
Running Tests
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install tox (myenv) $ tox
Development commands
pip install -r requirements_dev.txt invoke -l
Credits
Tools used in rendering this package:
History
0.2.0 (2023-08-15)
Fixes for new version of DDT (tested in 3.8.1 - 4.2.0)
Automatic testing
0.1.0 (2023-04-21)
First release on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dj_test_queries-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7fa16e124ccfbcae429278b4676c354236e86f5f009afb501cc9de0a5e71476 |
|
MD5 | b7d2375cf4afecb8c4a8894996e2f412 |
|
BLAKE2b-256 | c11254e420b832ed24315691d96e9f4ee6fe864a45c28f3903dc4691cc8215df |