Source

pytest-patches / multi-usageerror

Full commit
# HG changeset patch
# Parent f22b64ce811696019b7aea864e7d8bb44f965ce7

diff --git a/_pytest/main.py b/_pytest/main.py
--- a/_pytest/main.py
+++ b/_pytest/main.py
@@ -80,8 +80,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()
@@ -489,9 +490,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:
@@ -512,8 +516,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
--- 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):