Skip to content

Commit e26a198

Browse files
committed
Add link to query optimization docs
at the end of the --querycount report
1 parent e8f6c7f commit e26a198

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pytest_django/plugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,18 @@ def get_query_count(report):
413413
nodeid=nodeid
414414
))
415415

416+
import django
417+
major, minor = django.VERSION[0:2]
418+
419+
terminalreporter.write_line('')
420+
terminalreporter.write_line(
421+
'-- Docs: https://docs.djangoproject.com'
422+
'/en/{major}.{minor}/topics/db/optimization/'.format(
423+
major=major,
424+
minor=minor
425+
)
426+
)
427+
416428

417429
@pytest.fixture(autouse=True, scope='session')
418430
def django_test_environment(request):

tests/test_report.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,30 @@ def test_zero_queries():
3232
)
3333
assert 'tests with most queries' not in result.stdout.str()
3434

35+
def test_query_optimization_tips_for_the_current_version_of_django(
36+
self,
37+
django_testdir
38+
):
39+
django_testdir.create_test_module('''
40+
def test_zero_queries():
41+
pass
42+
''')
43+
44+
result = django_testdir.runpytest_subprocess('--querycount=5')
45+
46+
import django
47+
major, minor = django.VERSION[0:2]
48+
49+
url = (
50+
'https://docs.djangoproject.com'
51+
'/en/{major}.{minor}/topics/db/optimization/'
52+
).format(
53+
major=major,
54+
minor=minor
55+
)
56+
57+
assert url in result.stdout.str()
58+
3559
def test_querycount_report_lines(self, django_testdir):
3660
django_testdir.create_test_module('''
3761
import pytest

0 commit comments

Comments
 (0)