From e3b27926770ebc9b5127c7a987f67f39dade6224 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 1 Jun 2011 14:54:34 +0200 Subject: [PATCH] fix issue49 - avoid confusing errors when initialization goes wrong --- _pytest/main.py | 11 ++++++++--- testing/acceptance_test.py | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) 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("""