restrucure pytest.main.wrap_session to allow for non-testrun wraps
This commit is contained in:
parent
3d843edc69
commit
1e107e6bd1
|
@ -165,6 +165,7 @@ def pytest_cmdline_main(config):
|
||||||
return wrap_session(config, showcache)
|
return wrap_session(config, showcache)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(tryfirst=True)
|
@pytest.hookimpl(tryfirst=True)
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
config.cache = Cache(config)
|
config.cache = Cache(config)
|
||||||
|
|
|
@ -87,7 +87,7 @@ def wrap_session(config, doit):
|
||||||
initstate = 1
|
initstate = 1
|
||||||
config.hook.pytest_sessionstart(session=session)
|
config.hook.pytest_sessionstart(session=session)
|
||||||
initstate = 2
|
initstate = 2
|
||||||
doit(config, session)
|
session.exitstatus = doit(config, session) or 0
|
||||||
except pytest.UsageError:
|
except pytest.UsageError:
|
||||||
raise
|
raise
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
@ -100,11 +100,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")
|
||||||
else:
|
|
||||||
if session.testsfailed:
|
|
||||||
session.exitstatus = EXIT_TESTSFAILED
|
|
||||||
elif session.testscollected == 0:
|
|
||||||
session.exitstatus = EXIT_NOTESTSCOLLECTED
|
|
||||||
finally:
|
finally:
|
||||||
excinfo = None # Explicitly break reference cycle.
|
excinfo = None # Explicitly break reference cycle.
|
||||||
session.startdir.chdir()
|
session.startdir.chdir()
|
||||||
|
@ -124,6 +120,11 @@ def _main(config, session):
|
||||||
config.hook.pytest_collection(session=session)
|
config.hook.pytest_collection(session=session)
|
||||||
config.hook.pytest_runtestloop(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):
|
def pytest_collection(session):
|
||||||
return session.perform_collect()
|
return session.perform_collect()
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ def test_cache_show(testdir):
|
||||||
dp.ensure("world")
|
dp.ensure("world")
|
||||||
""")
|
""")
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
assert result.ret == 0
|
assert result.ret == 5 # no tests executed
|
||||||
result = testdir.runpytest("--show-cache")
|
result = testdir.runpytest("--show-cache")
|
||||||
result.stdout.fnmatch_lines_random([
|
result.stdout.fnmatch_lines_random([
|
||||||
"*cachedir:*",
|
"*cachedir:*",
|
||||||
|
|
Loading…
Reference in New Issue