Merged in RonnyPfannschmidt/pytest/multi-usageerror (pull request #113)
Make one usage error for every argument that fails instead of bailing at the first only
This commit is contained in:
commit
d53bfe0aa7
|
@ -80,7 +80,8 @@ def wrap_session(config, doit):
|
|||
initstate = 2
|
||||
doit(config, session)
|
||||
except pytest.UsageError:
|
||||
msg = sys.exc_info()[1].args[0]
|
||||
args = sys.exc_info()[1].args
|
||||
for msg in args:
|
||||
sys.stderr.write("ERROR: %s\n" %(msg,))
|
||||
session.exitstatus = EXIT_USAGEERROR
|
||||
except KeyboardInterrupt:
|
||||
|
@ -538,9 +539,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:
|
||||
|
@ -561,8 +565,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):
|
||||
|
|
|
@ -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*",
|
||||
])
|
||||
|
||||
def test_namespace_import_doesnt_confuse_import_hook(self, testdir):
|
||||
# Ref #383. Python 3.3's namespace package messed with our import hooks
|
||||
# Importing a module that didn't exist, even if the ImportError was
|
||||
|
|
Loading…
Reference in New Issue