handle exit code 2 as test failure
@@ -41,13 +41,25 @@ class PytestRunner(TestRunner):
with redirect_stdout(stdout):
exit_code = pytest.main(args, plugins=[collector])
+ # pytest exit codes:
+ # 0: All tests were collected and passed successfully
+ # 1: Tests were collected and run but some of the tests failed
+ # 2: Test execution was interrupted by the user
+ # This includes:
+ # - early abortion when using -x
+ # - errors during collection (https://github.com/pytest-dev/pytest/issues/2950)
+ # 3: Internal error happened while executing tests
+ # 4: pytest command line usage error
+ # 5: No tests were collected
+
if exit_code == 0:
return (True, ())
-
if exit_code == 1:
return (False, [(repr(r), r.longreprtext)
for r in collector.reports if r.failed])
-
+ if exit_code == 2:
+ return (False, [(repr(r), r.longreprtext)
+ for r in collector.reports if r.failed])
stdout.seek(0)
output = stdout.read()
raise TestRunnerFailure('pytest exited non-zero', exit_code, output)
