{"id":22129404,"url":"https://github.com/nyankiyoshi/pytest-django-queries","last_synced_at":"2026-03-10T00:31:42.093Z","repository":{"id":57456502,"uuid":"184709430","full_name":"NyanKiyoshi/pytest-django-queries","owner":"NyanKiyoshi","description":"Generate performance reports from your django database performance tests.","archived":false,"fork":false,"pushed_at":"2021-03-01T16:03:49.000Z","size":534,"stargazers_count":77,"open_issues_count":9,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T15:33:07.204Z","etag":null,"topics":["benchmark","benchmark-framework","benchmark-suite","benchmarking","performance-monitoring","pytest","pytest-django","pytest-plugin"],"latest_commit_sha":null,"homepage":"https://pytest-django-queries.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NyanKiyoshi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-03T06:35:58.000Z","updated_at":"2024-09-20T04:21:09.000Z","dependencies_parsed_at":"2022-09-14T05:20:58.285Z","dependency_job_id":null,"html_url":"https://github.com/NyanKiyoshi/pytest-django-queries","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyanKiyoshi%2Fpytest-django-queries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyanKiyoshi%2Fpytest-django-queries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyanKiyoshi%2Fpytest-django-queries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NyanKiyoshi%2Fpytest-django-queries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NyanKiyoshi","download_url":"https://codeload.github.com/NyanKiyoshi/pytest-django-queries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227606450,"owners_count":17792795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmark","benchmark-framework","benchmark-suite","benchmarking","performance-monitoring","pytest","pytest-django","pytest-plugin"],"created_at":"2024-12-01T17:59:48.745Z","updated_at":"2026-03-10T00:31:42.033Z","avatar_url":"https://github.com/NyanKiyoshi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align='center'\u003e\n  \u003ch1\u003epytest-django-queries\u003c/h1\u003e\n  \u003cp\u003eGenerate performance reports from your django database performance tests\n  (inspired by \u003ca href='https://coverage.readthedocs.io/en/v4.5.x/'\u003ecoverage.py\u003c/a\u003e).\u003c/p\u003e\n  \u003cp\u003e\n    \u003ca href='https://travis-ci.org/NyanKiyoshi/pytest-django-queries/'\u003e\n      \u003cimg src='https://travis-ci.org/NyanKiyoshi/pytest-django-queries.svg?branch=master' alt='Requirement Status' /\u003e\n    \u003c/a\u003e\n    \u003ca href='https://codecov.io/gh/NyanKiyoshi/pytest-django-queries'\u003e\n      \u003cimg src='https://codecov.io/gh/NyanKiyoshi/pytest-django-queries/branch/master/graph/badge.svg' alt='Coverage Status' /\u003e\n    \u003c/a\u003e\n    \u003ca href='https://pytest-django-queries.readthedocs.io/en/latest/?badge=latest'\u003e\n      \u003cimg src='https://readthedocs.org/projects/pytest-django-queries/badge/?version=latest' alt='Documentation Status' /\u003e\n    \u003c/a\u003e\n    \u003ca href='https://pypi.python.org/pypi/pytest-django-queries'\u003e\n      \u003cimg src='https://img.shields.io/pypi/v/pytest-django-queries.svg' alt='Version' /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/pytest-django-queries/1.2rc1/\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/pypi%20unstable-v1.2rc1-FF0000.svg\" alt=\"Latest Unstable on pypi\"\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003ca href='https://github.com/NyanKiyoshi/pytest-django-queries/compare/v1.2.0...master'\u003e\n      \u003cimg src='https://img.shields.io/github/commits-since/NyanKiyoshi/pytest-django-queries/v1.2.0.svg' alt='Commits since latest release' /\u003e\n    \u003c/a\u003e\n    \u003ca href='https://pypi.python.org/pypi/pytest-django-queries'\u003e\n      \u003cimg src='https://img.shields.io/pypi/pyversions/pytest-django-queries.svg' alt='Supported versions' /\u003e\n    \u003c/a\u003e\n    \u003ca href='https://pypi.python.org/pypi/pytest-django-queries'\u003e\n      \u003cimg src='https://img.shields.io/pypi/implementation/pytest-django-queries.svg' alt='Supported implementations' /\u003e\n    \u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n## Usage\nInstall `pytest-django-queries`, write your pytest tests and mark any\ntest that should be counted or use the `count_queries` fixture.\n\nNote: to use the latest development build, use `pip install --pre pytest-django-queries`\n\n```python\nimport pytest\n\n\n@pytest.mark.count_queries\ndef test_query_performances():\n    Model.objects.all()\n\n\n# Or...\ndef test_another_query_performances(count_queries):\n    Model.objects.all()\n```\n\nEach test file and/or package is considered as a category. Each test inside a \"category\"\ncompose its data, see [Visualising Results](#visualising-results) for more details.\n\nYou will find the [full documentation here](https://pytest-django-queries.readthedocs.io/).\n\n\u003c!-- TODO: insert a graphic here to explain how it works --\u003e\n\n## Recommendation when Using Fixtures\nYou might end up in the case where you want to add fixtures that are generating queries\nthat you don't want to be counted in the results–or simply, you want to use the\n`pytest-django` plugin alongside of `pytest-django-queries`, which will generate\nunwanted queries in your results.\n\nFor that, you will want to put the `count_queries` fixture as the last fixture to execute.\n\nBut at the same time, you might want to use the the power of pytest markers, to separate\nthe queries counting tests from other tests. In that case, you might want to do something\nlike this to tell the marker to not automatically inject the `count_queries` fixture into\nyour test:\n\n```python\nimport pytest\n\n\n@pytest.mark.count_queries(autouse=False)\ndef test_retrieve_main_menu(fixture_making_queries, count_queries):\n    pass\n```\n\nNotice the usage of the keyword argument `autouse=False` and the `count_queries` fixture\nbeing placed last.\n\n## Using pytest-django alongside of pytest-django-queries\nWe recommend you to do the following when using `pytest-django`:\n\n```python\nimport pytest\n\n\n@pytest.mark.django_db\n@pytest.mark.count_queries(autouse=False)\ndef test_retrieve_main_menu(any_fixture, other_fixture, count_queries):\n    pass\n```\n\n\n## Integrating with GitHub\n\nTBA.\n\n## Testing Locally\nSimply install `pytest-django-queries` through pip and run your\ntests using `pytest`. A report should have been generated in your\ncurrent working directory in a file called with `.pytest-queries`.\n\nNote: to override the save path, pass the `--django-db-bench PATH` option to pytest.\n\n## Visualising Results\nYou can generate a table from the tests results by using the `show` command:\n```shell\ndjango-queries show\n```\n\nYou will get something like this to represent the results:\n```shell\n+---------+--------------------------------------+\n| Module  |          Tests                       |\n+---------+--------------------------------------+\n| module1 | +-----------+---------+------------+ |\n|         | | Test Name | Queries | Duplicated | |\n|         | +-----------+---------+------------+ |\n|         | |   test1   |    0    |     0      | |\n|         | +-----------+---------+------------+ |\n|         | |   test2   |    1    |     0      | |\n|         | +-----------+---------+------------+ |\n+---------+--------------------------------------+\n| module2 | +-----------+---------+------------+ |\n|         | | Test Name | Queries | Duplicated | |\n|         | +-----------+---------+------------+ |\n|         | |   test1   |   123   |     0      | |\n|         | +-----------+---------+------------+ |\n+---------+--------------------------------------+\n```\n\n## Exporting the Results (HTML)\nFor a nicer presentation, use the `html` command, to export the results as HTML.\n```shell\ndjango-queries html\n```\n\nIt will generate something [like this](https://pytest-django-queries.readthedocs.io/en/latest/html_export_results.html).\n\n## Comparing Results\n\nYou can run `django-queries backup` (can take a path, optionally) after\nrunning your tests then rerun them. After that, you can run `django-queries diff`\nto generate results looking like this:\n\n\u003ca href='./docs/_static/diff_results.png'\u003e\n  \u003cimg src='./docs/_static/diff_results.png' alt='screenshot' width='500px' /\u003e\n\u003c/a\u003e\n\n## Development\nFirst of all, clone the project locally. Then, install it using the below command.\n\n```shell\n./setup.py develop\n```\n\nAfter that, you need to install the development and testing requirements. For that,\nrun the below command.\n\n```shell\npip install -e .[test]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyankiyoshi%2Fpytest-django-queries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnyankiyoshi%2Fpytest-django-queries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnyankiyoshi%2Fpytest-django-queries/lists"}