Skip to content

Commit e8f6c7f

Browse files
committed
Add --noquerycount parameter to disable --querycount
1 parent d4a990f commit e8f6c7f

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ to display a list of all tests ordered by the number of queries executed.
3737

3838
Using it in conjunction with `--setup-show` will display the number of
3939
queries executed by each fixture (when the number of queries executed by the
40-
fixture is greater than zero).
40+
fixture is greater than zero). Use `--noquerycount` to force the disable of it.
4141

4242
Running tests in parallel with pytest-xdist
4343
-------------------------------------------

pytest_django/plugin.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,14 @@ def pytest_addoption(parser):
8585
type='bool', default=False)
8686

8787
group._addoption('--querycount',
88-
action='store', type=int, default=None, metavar='N',
88+
action='store', dest='querycount', type=int,
89+
default=None, metavar='N',
8990
help='Show top N tests with most queries '
9091
'(N=0 for all).')
92+
group._addoption('--noquerycount', '--no-querycount',
93+
action='store_const', dest='querycount',
94+
const=None, default=None,
95+
help='Disable --querycount, when both are used.')
9196

9297

9398
def _exists(path, ignore=EnvironmentError):

tests/test_report.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,18 @@ def test_zero_queries():
1919
''')
2020

2121
result = django_testdir.runpytest_subprocess()
22-
assert 'top tests with most queries' not in result.stdout.str()
22+
assert 'tests with most queries' not in result.stdout.str()
23+
24+
def test_disabled_when_noquerycount_is_also_used(self, django_testdir):
25+
django_testdir.create_test_module('''
26+
def test_zero_queries():
27+
pass
28+
''')
29+
30+
result = django_testdir.runpytest_subprocess(
31+
'--querycount=5 --noquerycount'
32+
)
33+
assert 'tests with most queries' not in result.stdout.str()
2334

2435
def test_querycount_report_lines(self, django_testdir):
2536
django_testdir.create_test_module('''

0 commit comments

Comments
 (0)