From 6cb1ae00b17114e76285342cd6dc97aa984f1b7b Mon Sep 17 00:00:00 2001 From: Thomas Hisch Date: Tue, 13 Feb 2018 14:46:11 +0100 Subject: [PATCH] Show deselection count before tests are exectued Fixes #1527 --- _pytest/terminal.py | 10 ++++------ changelog/3213.feature | 1 + testing/test_terminal.py | 27 ++++++++++++++++++++++++++- 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 changelog/3213.feature diff --git a/_pytest/terminal.py b/_pytest/terminal.py index d37dd2c433a..69d4ab8add1 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -361,6 +361,7 @@ 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: @@ -368,6 +369,8 @@ def report_collect(self, final=False): 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: @@ -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) @@ -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): @@ -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: diff --git a/changelog/3213.feature b/changelog/3213.feature new file mode 100644 index 00000000000..755942f1b68 --- /dev/null +++ b/changelog/3213.feature @@ -0,0 +1 @@ +Output item deselection count before tests are run. \ No newline at end of file diff --git a/testing/test_terminal.py b/testing/test_terminal.py index e95a3ed2b6a..f23dffe2524 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -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