fix issue143 - call unconfigure/sessionfinish always when

configure/sessionstart where called

use exitcode 4 (instead of 3 which signaled an internal error)
when an initial directory/file was not found
This commit is contained in:
holger krekel 2012-05-17 23:11:23 +02:00
parent 6c7ea8191f
commit e18abfd013
6 changed files with 53 additions and 32 deletions

View File

@ -10,6 +10,8 @@ Changes between 2.2.3 and 2.2.4
- fix issue 140: propperly get the real functions - fix issue 140: propperly get the real functions
of bound classmethods for setup/teardown_class of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net - fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called
Changes between 2.2.2 and 2.2.3 Changes between 2.2.2 and 2.2.3
---------------------------------------- ----------------------------------------

View File

@ -465,13 +465,8 @@ def main(args=None, plugins=None):
""" returned exit code integer, after an in-process testing run """ returned exit code integer, after an in-process testing run
with the given command line arguments, preloading an optional list with the given command line arguments, preloading an optional list
of passed in plugin objects. """ of passed in plugin objects. """
try: config = _prepareconfig(args, plugins)
config = _prepareconfig(args, plugins) exitstatus = config.hook.pytest_cmdline_main(config=config)
exitstatus = config.hook.pytest_cmdline_main(config=config)
except UsageError:
e = sys.exc_info()[1]
sys.stderr.write("ERROR: %s\n" %(e.args[0],))
exitstatus = 3
return exitstatus return exitstatus
class UsageError(Exception): class UsageError(Exception):

View File

@ -10,6 +10,7 @@ EXIT_OK = 0
EXIT_TESTSFAILED = 1 EXIT_TESTSFAILED = 1
EXIT_INTERRUPTED = 2 EXIT_INTERRUPTED = 2
EXIT_INTERNALERROR = 3 EXIT_INTERNALERROR = 3
EXIT_USAGEERROR = 4
name_re = py.std.re.compile("^[a-zA-Z_]\w*$") name_re = py.std.re.compile("^[a-zA-Z_]\w*$")
@ -65,30 +66,34 @@ def wrap_session(config, doit):
session.exitstatus = EXIT_OK session.exitstatus = EXIT_OK
initstate = 0 initstate = 0
try: try:
config.pluginmanager.do_configure(config) try:
initstate = 1 config.pluginmanager.do_configure(config)
config.hook.pytest_sessionstart(session=session) initstate = 1
initstate = 2 config.hook.pytest_sessionstart(session=session)
doit(config, session) initstate = 2
except pytest.UsageError: doit(config, session)
raise except pytest.UsageError:
except KeyboardInterrupt: msg = sys.exc_info()[1].args[0]
excinfo = py.code.ExceptionInfo() sys.stderr.write("ERROR: %s\n" %(msg,))
config.hook.pytest_keyboard_interrupt(excinfo=excinfo) session.exitstatus = EXIT_USAGEERROR
session.exitstatus = EXIT_INTERRUPTED except KeyboardInterrupt:
except: excinfo = py.code.ExceptionInfo()
excinfo = py.code.ExceptionInfo() config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
config.pluginmanager.notify_exception(excinfo, config.option) session.exitstatus = EXIT_INTERRUPTED
session.exitstatus = EXIT_INTERNALERROR except:
if excinfo.errisinstance(SystemExit): excinfo = py.code.ExceptionInfo()
sys.stderr.write("mainloop: caught Spurious SystemExit!\n") config.pluginmanager.notify_exception(excinfo, config.option)
if initstate >= 2: session.exitstatus = EXIT_INTERNALERROR
config.hook.pytest_sessionfinish(session=session, if excinfo.errisinstance(SystemExit):
exitstatus=session.exitstatus or (session._testsfailed and 1)) sys.stderr.write("mainloop: caught Spurious SystemExit!\n")
if not session.exitstatus and session._testsfailed: finally:
session.exitstatus = EXIT_TESTSFAILED if initstate >= 2:
if initstate >= 1: config.hook.pytest_sessionfinish(session=session,
config.pluginmanager.do_unconfigure(config) exitstatus=session.exitstatus or (session._testsfailed and 1))
if not session.exitstatus and session._testsfailed:
session.exitstatus = EXIT_TESTSFAILED
if initstate >= 1:
config.pluginmanager.do_unconfigure(config)
return session.exitstatus return session.exitstatus
def pytest_cmdline_main(config): def pytest_cmdline_main(config):

View File

@ -32,3 +32,6 @@ Changes between 2.2.3 and 2.2.4
- fix issue 140: propperly get the real functions - fix issue 140: propperly get the real functions
of bound classmethods for setup/teardown_class of bound classmethods for setup/teardown_class
- fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net - fix issue #141: switch from the deceased paste.pocoo.org to bpaste.net
- fix issue #143: call unconfigure/sessionfinish always when
configure/sessionstart where called

View File

@ -57,6 +57,22 @@ class TestGeneralUsage:
assert result.ret != 0 assert result.ret != 0
result.stderr.fnmatch_lines(["ERROR: file not found*asd"]) result.stderr.fnmatch_lines(["ERROR: file not found*asd"])
def test_file_not_found_unconfigure_issue143(self, testdir):
testdir.makeconftest("""
def pytest_configure():
print("---configure")
def pytest_unconfigure():
print("---unconfigure")
""")
result = testdir.runpytest("-s", "asd")
assert result.ret == 4 # EXIT_USAGEERROR
result.stderr.fnmatch_lines(["ERROR: file not found*asd"])
s = result.stdout.fnmatch_lines([
"*---configure",
"*---unconfigure",
])
def test_config_preparse_plugin_option(self, testdir): def test_config_preparse_plugin_option(self, testdir):
testdir.makepyfile(pytest_xyz=""" testdir.makepyfile(pytest_xyz="""
def pytest_addoption(parser): def pytest_addoption(parser):

View File

@ -262,7 +262,7 @@ class TestCollectonly:
not to have the items attribute not to have the items attribute
""" """
result = testdir.runpytest("--collectonly", "uhm_missing_path") result = testdir.runpytest("--collectonly", "uhm_missing_path")
assert result.ret == 3 assert result.ret == 4
result.stderr.fnmatch_lines([ result.stderr.fnmatch_lines([
'*ERROR: file not found*', '*ERROR: file not found*',
]) ])