django-perf-rec
raw JSON → 4.31.0 verified Mon Apr 27 auth: no python
A Django library for recording and asserting performance characteristics of your code over time. It provides a Python context manager and Django test case mixin to record per-request SQL query counts and durations, template node counts, and response sizes. Version 4.31.0 supports Python 3.9+ and Django 3.2+. The project is actively maintained with a regular release cadence.
pip install django-perf-rec Common errors
error ImportError: cannot import name 'record' from 'django_perf_rec' ↓
cause The record() context manager was removed in version 4.0.0.
fix
Use RecordRequestsMixin for test classes or record_requests() for context manager.
error ModuleNotFoundError: No module named 'django_perf_rec' ↓
cause Library not installed or installed in wrong environment.
fix
Run 'pip install django-perf-rec' in your Python environment.
Warnings
gotcha RecordRequestsMixin must be listed before TestCase in the base class order to work correctly. ↓
fix Ensure mixin order: class MyTestCase(RecordRequestsMixin, TestCase):
breaking In version 4.0.0, the record() context manager was removed. Use the RecordRequestsMixin or record_requests() instead. ↓
fix Upgrade to use RecordRequestsMixin for test classes or record_requests() for context managers.
deprecated The attribute 'assertNumQueries' is deprecated in favor of 'assertNumQueries' but may be removed in a future version. ↓
fix Use assertNumQueries with the same signature.
Imports
- RecordRequestsMixin wrong
from django_perf_rec.mixin import RecordRequestsMixincorrectfrom django_perf_rec import RecordRequestsMixin
Quickstart
from django_perf_rec import RecordRequestsMixin
from django.test import TestCase
class MyTestCase(RecordRequestsMixin, TestCase):
def test_view(self):
response = self.client.get('/')
self.assertNumQueries(5) # autmoatically records baseline
self.assertTemplateUsed('index.html')