Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show deselection count before tests are executed #3213

Merged
merged 2 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,16 @@ def report_collect(self, final=False):

errors = len(self.stats.get('error', []))
skipped = len(self.stats.get('skipped', []))
deselected = len(self.stats.get('deselected', []))
if final:
line = "collected "
else:
line = "collecting "
line += str(self._numcollected) + " item" + ('' if self._numcollected == 1 else 's')
if errors:
line += " / %d errors" % errors
if deselected:
line += " / %d deselected" % deselected
if skipped:
line += " / %d skipped" % skipped
if self.isatty:
Expand All @@ -377,6 +380,7 @@ def report_collect(self, final=False):
else:
self.write_line(line)

@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(self):
self.report_collect(True)

Expand Down Expand Up @@ -484,7 +488,6 @@ def pytest_sessionfinish(self, exitstatus):
if exitstatus == EXIT_INTERRUPTED:
self._report_keyboardinterrupt()
del self._keyboardinterrupt_memo
self.summary_deselected()
self.summary_stats()

def pytest_keyboard_interrupt(self, excinfo):
Expand Down Expand Up @@ -649,11 +652,6 @@ def summary_stats(self):
if self.verbosity == -1:
self.write_line(msg, **markup)

def summary_deselected(self):
if 'deselected' in self.stats:
self.write_sep("=", "%d tests deselected" % (
len(self.stats['deselected'])), bold=True)


def repr_pythonversion(v=None):
if v is None:
Expand Down
1 change: 1 addition & 0 deletions changelog/3213.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deselected item count is now shown before tests are run, e.g. ``collected X items / Y deselected``.
2 changes: 1 addition & 1 deletion testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def test_b2():

result = testdir.runpytest('--lf')
result.stdout.fnmatch_lines([
'collected 4 items',
'collected 4 items / 2 deselected',
'run-last-failure: rerun previous 2 failures',
'*2 failed, 2 deselected in*',
])
Expand Down
27 changes: 26 additions & 1 deletion testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,36 @@ def test_three():
)
result = testdir.runpytest("-k", "test_two:", testpath)
result.stdout.fnmatch_lines([
"collected 3 items / 1 deselected",
"*test_deselected.py ..*",
"=* 1 test*deselected *=",
])
assert result.ret == 0

def test_show_deselected_items_using_markexpr_before_test_execution(
self, testdir):
testdir.makepyfile("""
import pytest

@pytest.mark.foo
def test_foobar():
pass

@pytest.mark.bar
def test_bar():
pass

def test_pass():
pass
""")
result = testdir.runpytest('-m', 'not foo')
result.stdout.fnmatch_lines([
"collected 3 items / 1 deselected",
"*test_show_des*.py ..*",
"*= 2 passed, 1 deselected in * =*",
])
assert "= 1 deselected =" not in result.stdout.str()
assert result.ret == 0

def test_no_skip_summary_if_failure(self, testdir):
testdir.makepyfile("""
import pytest
Expand Down