diff --git a/_pytest/main.py b/_pytest/main.py index a8645f4f3..ac306a867 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -58,9 +58,12 @@ def wrap_session(config, doit): """Skeleton command line program""" session = Session(config) session.exitstatus = EXIT_OK + initstate = 0 try: config.pluginmanager.do_configure(config) + initstate = 1 config.hook.pytest_sessionstart(session=session) + initstate = 2 doit(config, session) except pytest.UsageError: raise @@ -76,9 +79,11 @@ def wrap_session(config, doit): sys.stderr.write("mainloop: caught Spurious SystemExit!\n") if not session.exitstatus and session._testsfailed: session.exitstatus = EXIT_TESTSFAILED - config.hook.pytest_sessionfinish(session=session, - exitstatus=session.exitstatus) - config.pluginmanager.do_unconfigure(config) + if initstate >= 2: + config.hook.pytest_sessionfinish(session=session, + exitstatus=session.exitstatus) + if initstate >= 1: + config.pluginmanager.do_unconfigure(config) return session.exitstatus def pytest_cmdline_main(config): diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 703647087..1e12f1272 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -259,6 +259,19 @@ class TestGeneralUsage: if name.startswith("pytest_"): assert value.__doc__, "no docstring for %s" % name + def test_initialization_error_issue49(self, testdir): + testdir.makeconftest(""" + def pytest_configure(): + x + """) + result = testdir.runpytest() + assert result.ret == 3 # internal error + result.stderr.fnmatch_lines([ + "INTERNAL*pytest_configure*", + "INTERNAL*x*", + ]) + assert 'sessionstarttime' not in result.stderr.str() + class TestInvocationVariants: def test_earlyinit(self, testdir): p = testdir.makepyfile("""