diff --git a/_pytest/terminal.py b/_pytest/terminal.py index b833886b5..6584179e6 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -331,7 +331,7 @@ class TerminalReporter: def pytest_sessionfinish(self, exitstatus, __multicall__): __multicall__.execute() self._tw.line("") - if exitstatus in (0, 1, 2): + if exitstatus in (0, 1, 2, 4): self.summary_errors() self.summary_failures() self.config.hook.pytest_terminal_summary(terminalreporter=self) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 623f29b27..e61b5070a 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -294,6 +294,21 @@ class TestGeneralUsage: ]) assert 'sessionstarttime' not in result.stderr.str() + @pytest.mark.parametrize('lookfor', ['test_fun.py', 'test_fun.py::test_a']) + def test_issue134_report_syntaxerror_when_collecting_member(self, testdir, lookfor): + testdir.makepyfile(test_fun=""" + def test_a(): + pass + def""") + result = testdir.runpytest(lookfor) + result.stdout.fnmatch_lines(['*SyntaxError*']) + if '::' in lookfor: + result.stderr.fnmatch_lines([ + '*ERROR*', + ]) + assert result.ret == 4 # usage error only if item not found + + class TestInvocationVariants: def test_earlyinit(self, testdir): p = testdir.makepyfile("""