Skip to content

Commit ffc35ea

Browse files
renanivoblueyed
authored andcommitted
Add link to query optimization docs
at the end of the --querycount report
1 parent e646ae9 commit ffc35ea

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
@@ -432,6 +432,18 @@ def get_query_count(report):
432432
nodeid=nodeid
433433
))
434434

435+
import django
436+
major, minor = django.VERSION[0:2]
437+
438+
terminalreporter.write_line('')
439+
terminalreporter.write_line(
440+
'-- Docs: https://docs.djangoproject.com'
441+
'/en/{major}.{minor}/topics/db/optimization/'.format(
442+
major=major,
443+
minor=minor
444+
)
445+
)
446+
435447

436448
@pytest.fixture(autouse=True, scope='session')
437449
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)