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*$")
@ -64,6 +65,7 @@ def wrap_session(config, doit):
session = Session(config) session = Session(config)
session.exitstatus = EXIT_OK session.exitstatus = EXIT_OK
initstate = 0 initstate = 0
try:
try: try:
config.pluginmanager.do_configure(config) config.pluginmanager.do_configure(config)
initstate = 1 initstate = 1
@ -71,7 +73,9 @@ def wrap_session(config, doit):
initstate = 2 initstate = 2
doit(config, session) doit(config, session)
except pytest.UsageError: except pytest.UsageError:
raise msg = sys.exc_info()[1].args[0]
sys.stderr.write("ERROR: %s\n" %(msg,))
session.exitstatus = EXIT_USAGEERROR
except KeyboardInterrupt: except KeyboardInterrupt:
excinfo = py.code.ExceptionInfo() excinfo = py.code.ExceptionInfo()
config.hook.pytest_keyboard_interrupt(excinfo=excinfo) config.hook.pytest_keyboard_interrupt(excinfo=excinfo)
@ -82,6 +86,7 @@ def wrap_session(config, doit):
session.exitstatus = EXIT_INTERNALERROR session.exitstatus = EXIT_INTERNALERROR
if excinfo.errisinstance(SystemExit): if excinfo.errisinstance(SystemExit):
sys.stderr.write("mainloop: caught Spurious SystemExit!\n") sys.stderr.write("mainloop: caught Spurious SystemExit!\n")
finally:
if initstate >= 2: if initstate >= 2:
config.hook.pytest_sessionfinish(session=session, config.hook.pytest_sessionfinish(session=session,
exitstatus=session.exitstatus or (session._testsfailed and 1)) exitstatus=session.exitstatus or (session._testsfailed and 1))

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*',
]) ])