From 81018f199636e710b92bcc44af68e7860f80d672 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Thu, 27 Aug 2015 19:22:22 +0200 Subject: [PATCH] restrucure pytest.main.wrap_session to allow for non-testrun wraps --- _pytest/main.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/_pytest/main.py b/_pytest/main.py index 6b2ccb6b7..e9ac57d8f 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -87,7 +87,7 @@ def wrap_session(config, doit): initstate = 1 config.hook.pytest_sessionstart(session=session) initstate = 2 - doit(config, session) + session.exitstatus = doit(config, session) or 0 except pytest.UsageError: raise except KeyboardInterrupt: @@ -100,11 +100,7 @@ def wrap_session(config, doit): session.exitstatus = EXIT_INTERNALERROR if excinfo.errisinstance(SystemExit): sys.stderr.write("mainloop: caught Spurious SystemExit!\n") - else: - if session.testsfailed: - session.exitstatus = EXIT_TESTSFAILED - elif session.testscollected == 0: - session.exitstatus = EXIT_NOTESTSCOLLECTED + finally: excinfo = None # Explicitly break reference cycle. session.startdir.chdir() @@ -124,6 +120,11 @@ def _main(config, session): config.hook.pytest_collection(session=session) config.hook.pytest_runtestloop(session=session) + if session.testsfailed: + return EXIT_TESTSFAILED + elif session.testscollected == 0: + return EXIT_NOTESTSCOLLECTED + def pytest_collection(session): return session.perform_collect()