Skip to content

Commit 6496131

Browse files
committed
Show deselection count before tests are exectued
Fixes #1527
1 parent 063e2da commit 6496131

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

_pytest/terminal.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,16 @@ def report_collect(self, final=False):
361361

362362
errors = len(self.stats.get('error', []))
363363
skipped = len(self.stats.get('skipped', []))
364+
deselected = len(self.stats.get('deselected', []))
364365
if final:
365366
line = "collected "
366367
else:
367368
line = "collecting "
368369
line += str(self._numcollected) + " item" + ('' if self._numcollected == 1 else 's')
369370
if errors:
370371
line += " / %d errors" % errors
372+
if deselected:
373+
line += " / %d deselected" % deselected
371374
if skipped:
372375
line += " / %d skipped" % skipped
373376
if self.isatty:
@@ -377,6 +380,7 @@ def report_collect(self, final=False):
377380
else:
378381
self.write_line(line)
379382

383+
@pytest.hookimpl(trylast=True)
380384
def pytest_collection_modifyitems(self):
381385
self.report_collect(True)
382386

@@ -484,7 +488,6 @@ def pytest_sessionfinish(self, exitstatus):
484488
if exitstatus == EXIT_INTERRUPTED:
485489
self._report_keyboardinterrupt()
486490
del self._keyboardinterrupt_memo
487-
self.summary_deselected()
488491
self.summary_stats()
489492

490493
def pytest_keyboard_interrupt(self, excinfo):
@@ -649,11 +652,6 @@ def summary_stats(self):
649652
if self.verbosity == -1:
650653
self.write_line(msg, **markup)
651654

652-
def summary_deselected(self):
653-
if 'deselected' in self.stats:
654-
self.write_sep("=", "%d tests deselected" % (
655-
len(self.stats['deselected'])), bold=True)
656-
657655

658656
def repr_pythonversion(v=None):
659657
if v is None:

changelog/3213.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Output item deselection count before tests are run.

testing/test_cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def test_b2():
361361

362362
result = testdir.runpytest('--lf')
363363
result.stdout.fnmatch_lines([
364-
'collected 4 items',
364+
'collected 4 items / 2 deselected',
365365
'run-last-failure: rerun previous 2 failures',
366366
'*2 failed, 2 deselected in*',
367367
])

testing/test_terminal.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,36 @@ def test_three():
431431
)
432432
result = testdir.runpytest("-k", "test_two:", testpath)
433433
result.stdout.fnmatch_lines([
434+
"collected 3 items / 1 deselected",
434435
"*test_deselected.py ..*",
435-
"=* 1 test*deselected *=",
436436
])
437437
assert result.ret == 0
438438

439+
def test_show_deselected_items_using_markexpr_before_test_execution(
440+
self, testdir):
441+
testdir.makepyfile("""
442+
import pytest
443+
444+
@pytest.mark.foo
445+
def test_foobar():
446+
pass
447+
448+
@pytest.mark.bar
449+
def test_bar():
450+
pass
451+
452+
def test_pass():
453+
pass
454+
""")
455+
result = testdir.runpytest('-m', 'not foo')
456+
result.stdout.fnmatch_lines([
457+
"collected 3 items / 1 deselected",
458+
"*test_show_des*.py ..*",
459+
"*= 2 passed, 1 deselected in * =*",
460+
])
461+
assert "= 1 deselected =" not in result.stdout.str()
462+
assert result.ret == 0
463+
439464
def test_no_skip_summary_if_failure(self, testdir):
440465
testdir.makepyfile("""
441466
import pytest

0 commit comments

Comments
 (0)