Decorator for measuring the time and number of database queries
Project description
Decorator for measuring the time and number of database queries
Provides a decorator for measuring the time and number of database queries
Requirements
- django>=4.2.11
Install
pip install capture-db-queries
About decorator
capture_db_queries capture_queries
it can call the body of the decorated function the specified number of times for multiple measurements, it can validate the total number of queries.
- Optional parameters:
assert_q_count
: The expected number of database requests is otherwise "AssertionError: N not less than or equal to N queries"number_runs
: The number of runs of the test function_
verbose
: Displaying the final results of the test measurementsadvanced_verb
: Displaying the result of each test measurementqueries
: Displaying raw SQL queries to the database
About context manager
ExtCaptureQueriesContext
- Optional parameters:
assert_q_count
: The expected number of database requests is otherwise "AssertionError: N not less than or equal to N queries"verbose
: Displaying the final results of the test measurementsqueries
: Displaying raw SQL queries to the database
Usage example
Direct usage
from capture_db_queries.decoratos import capture_queries
@capture_queries(number_runs=2, advanced_verb=True)
def _():
response = self.client.get(url)
>>> Test в„–1 | Queries count: 10 | Execution time: 0.04s
>>> Test в„–2 | Queries count: 10 | Execution time: 0.04s
>>> Tests count: 2 | Total queries count: 20 | Total execution time: 0.08s | Median time one test is: 0.041s
with ExtCaptureQueriesContext():
response = self.client.get(url)
>>> Queries count: 164 | Execution time: 0.923s
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
Close
Hashes for capture_db_queries-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 039973a40cf77d6a5b05ad6d4bbf0ff51cbf23ed5d8617da7a27dd04b997c30d |
|
MD5 | 69d819d3e83b8c1af422ab50ede2c16e |
|
BLAKE2b-256 | 5121013647c6c67f929d71ae258329fcc2f105c5ed7be296b18e36cdd7d50cb6 |