From cf37c477bbfdf266f8d821ffc09b9661dbf252c3 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 8 Sep 2013 22:26:51 +0200 Subject: [PATCH] output errors for all failures of specific collection when issueing a command with many specific items to collect, print all collect failures instead of just the first one --HG-- branch : multi-usageerror --- _pytest/main.py | 13 ++++++++----- testing/acceptance_test.py | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/_pytest/main.py b/_pytest/main.py index 008d39c3a..5a9b0488e 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -82,8 +82,9 @@ def wrap_session(config, doit): initstate = 2 doit(config, session) except pytest.UsageError: - msg = sys.exc_info()[1].args[0] - sys.stderr.write("ERROR: %s\n" %(msg,)) + args = sys.exc_info()[1].args + for msg in args: + sys.stderr.write("ERROR: %s\n" %(msg,)) session.exitstatus = EXIT_USAGEERROR except KeyboardInterrupt: excinfo = py.code.ExceptionInfo() @@ -516,9 +517,12 @@ class Session(FSCollector): self.ihook.pytest_collectreport(report=rep) self.trace.root.indent -= 1 if self._notfound: + errors = [] for arg, exc in self._notfound: line = "(no name %r in any of %r)" % (arg, exc.args[0]) - raise pytest.UsageError("not found: %s\n%s" %(arg, line)) + errors.append("not found: %s\n%s" % (arg, line)) + #XXX: test this + raise pytest.UsageError(*errors) if not genitems: return rep.result else: @@ -539,8 +543,7 @@ class Session(FSCollector): # we are inside a make_report hook so # we cannot directly pass through the exception self._notfound.append((arg, sys.exc_info()[1])) - self.trace.root.indent -= 1 - break + self.trace.root.indent -= 1 def _collect(self, arg): diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 295fe3080..67e4a6ba0 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -308,6 +308,14 @@ class TestGeneralUsage: ]) assert result.ret == 4 # usage error only if item not found + def test_report_all_failed_collections_initargs(self, testdir): + testdir.makepyfile(test_a="def", test_b="def") + result = testdir.runpytest("test_a.py::a", "test_b.py::b") + result.stderr.fnmatch_lines([ + "*ERROR*test_a.py::a*", + "*ERROR*test_b.py::b*", + ]) + class TestInvocationVariants: def test_earlyinit(self, testdir):