Generate performance rapports from your django database performance tests.
Project description
pytest-django-queries
Generate performance rapports from your django database performance tests (inspired by coverage.py).
Usage
Install pytest-django-queries
, write your pytest tests and mark any
test that should be counted or use the count_queries
fixture.
Note: to use the latest development build, use pip install --pre pytest-django-queries
import pytest
@pytest.mark.count_queries
def test_query_performances():
Model.objects.all()
# Or...
def test_another_query_performances(count_queries):
Model.objects.all()
Each test file and/or package is considered as a category. Each test inside a "category" compose its data, see Visualising Results for more details.
You will find the full documentation here.
Integrating with GitHub
TBA.
Testing locally
Simply install pytest-django-queries
through pip and run your
tests using pytest
. A report should have been generated in your
current working directory in a file called with .pytest-queries
.
Note: to override the save path, pass the --django-db-bench PATH
option to pytest.
Visualising Results
You can generate a table from the tests results by using the show
command:
django-queries show
You will get something like this to represent the results:
+---------+-------------------------+
| Module | Tests |
+---------+-------------------------+
| module1 | +-----------+---------+ |
| | | Test Name | Queries | |
| | +-----------+---------+ |
| | | test1 | 0 | |
| | +-----------+---------+ |
| | | test2 | 1 | |
| | +-----------+---------+ |
+---------+-------------------------+
| module2 | +-----------+---------+ |
| | | Test Name | Queries | |
| | +-----------+---------+ |
| | | test1 | 123 | |
| | +-----------+---------+ |
+---------+-------------------------+
| module3 | |
+---------+-------------------------+
Exporting the results (HTML)
For a nicer presentation, use the html
command, to export the results as HTML.
django-queries html
It will generate something like this.
Comparing results
When running pytest, pass the --django-backup-queries
(can take a path, optionally)
then you can run django-queries diff
to generate results looking like this:
Development
First of all, clone the project locally. Then, install it using the below command.
./setup.py develop
After that, you need to install the development requirements. For that, run the below command.
pip install -e .[dev]
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
Hashes for pytest-django-queries-1.0.0rc1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03e76e458062d2e7335c87b719d0eb74f7257abbe54f49fb96a28ef2d3fbc602 |
|
MD5 | fb71fbafc2d2940c4a28bf274995d371 |
|
BLAKE2b-256 | 03f6ff2026c35567948c0033f3184154bcff976b8f36c62a78ec315d41e27a25 |