* rename testrunstart/finish to sessionstart and pass it an argument

* simplify pyexecnetcleanup plugin

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-22 21:53:26 +02:00
parent bcd9aed0b1
commit db2ef3e9e8
7 changed files with 29 additions and 38 deletions

View File

@ -365,7 +365,7 @@ class TestDSession:
# see that the node is really down
node = hookrecorder.popcall("pytest_testnodedown").node
assert node.gateway.spec.popen
#XXX eq.geteventargs("pytest_testrunfinish")
#XXX eq.geteventargs("pytest_sessionfinish")
@py.test.mark.xfail("test implementation missing")
def test_collected_function_causes_remote_skip_at_module_level(self, testdir):

View File

@ -23,17 +23,15 @@ class PluginHooks:
# test Session related hooks
# ------------------------------------------------------------------------------
def pytest_testrunstart(self):
""" whole test run starts. """
def pytest_sessionstart(self, session):
""" before session.main() is called. """
def pytest_testrunfinish(self, exitstatus, excrepr=None):
def pytest_sessionfinish(self, session, exitstatus, excrepr=None):
""" whole test run finishes. """
def pytest_deselected(self, items):
""" collected items that were deselected (by keyword). """
# ------------------------------------------------------------------------------
# collection hooks
# ------------------------------------------------------------------------------

View File

@ -4,34 +4,25 @@ cleanup gateways that were instantiated during a test function run.
import py
def pytest_configure(config):
debug = config.option.debug
config.pluginmanager.register(Execnetcleanup(debug))
config.pluginmanager.register(Execnetcleanup())
class Execnetcleanup:
_gateways = None
def __init__(self, debug=False):
self._debug = debug
def trace(self, msg, *args):
if self._debug:
print "[execnetcleanup %0x] %s %s" %(id(self), msg, args)
def pyexecnet_gateway_init(self, gateway):
self.trace("init", gateway)
if self._gateways is not None:
self._gateways.append(gateway)
def pyexecnet_gateway_exit(self, gateway):
self.trace("exit", gateway)
if self._gateways is not None:
self._gateways.remove(gateway)
def pytest_testrunstart(self):
self.trace("testrunstart")
def pytest_sessionstart(self, session):
self._gateways = []
def pytest_testrunfinish(self, exitstatus, excrepr=None):
self.trace("testrunfinish", exitstatus)
def pytest_sessionfinish(self, session, exitstatus, excrepr=None):
l = []
for gw in self._gateways:
gw.exit()

View File

@ -31,6 +31,6 @@ def test_functional(testdir):
""")
testdir.runpytest("--hooklog=hook.log")
s = testdir.tmpdir.join("hook.log").read()
assert s.find("pytest_testrunstart") != -1
assert s.find("pytest_sessionstart") != -1
assert s.find("ItemTestReport") != -1
assert s.find("testrunfinish") != -1
assert s.find("sessionfinish") != -1

View File

@ -61,7 +61,7 @@ class PluginTester:
for arg, hookarg in zip(method_args[0], hookargs[0]):
if arg != hookarg:
print "argument mismatch:"
print "actual : %s.%s" %(pluginclass.__name__, formatdef(method))
print "actual : %s.%s" %(plugin.__name__, formatdef(method))
print "required:", formatdef(hook)
fail = True
break

View File

@ -194,7 +194,7 @@ class TerminalReporter:
self.stats.setdefault("skipped", []).append(rep)
self.write_fspath_result(rep.collector.fspath, "S")
def pytest_testrunstart(self):
def pytest_sessionstart(self, session):
self.write_sep("=", "test session starts", bold=True)
self._sessionstarttime = py.std.time.time()
@ -225,7 +225,7 @@ class TerminalReporter:
for i, testarg in py.builtin.enumerate(self.config.args):
self.write_line("test object %d: %s" %(i+1, testarg))
def pytest_testrunfinish(self, exitstatus, excrepr=None):
def pytest_sessionfinish(self, session, exitstatus, excrepr=None):
self._tw.line("")
if exitstatus in (0, 1, 2):
self.summary_failures()
@ -285,7 +285,7 @@ class TerminalReporter:
return reportinfo
#
# summaries for testrunfinish
# summaries for sessionfinish
#
def summary_failures(self):
@ -362,7 +362,7 @@ class CollectonlyReporter:
self._failed.append(rep)
self.indent = self.indent[:-len(self.INDENT)]
def pytest_testrunfinish(self, exitstatus, excrepr=None):
def pytest_sessionfinish(self, session, exitstatus, excrepr=None):
if self._failed:
self.out.sep("!", "collection failures")
for rep in self._failed:
@ -409,7 +409,7 @@ class TestTerminal:
""")
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
rep.config.pluginmanager.register(rep)
rep.config.hook.pytest_testrunstart()
rep.config.hook.pytest_sessionstart(session=testdir.session)
for item in testdir.genitems([modcol]):
ev = runner.basic_run_report(item)
@ -417,7 +417,7 @@ class TestTerminal:
linecomp.assert_contains_lines([
"*test_pass_skip_fail.py .sF"
])
rep.config.hook.pytest_testrunfinish(exitstatus=1)
rep.config.hook.pytest_sessionfinish(session=testdir.session, exitstatus=1)
linecomp.assert_contains_lines([
" def test_func():",
"> assert 0",
@ -436,7 +436,7 @@ class TestTerminal:
""", configargs=("-v",))
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
rep.config.pluginmanager.register(rep)
rep.config.hook.pytest_testrunstart()
rep.config.hook.pytest_sessionstart(session=testdir.session)
items = modcol.collect()
rep.config.option.debug = True #
for item in items:
@ -450,7 +450,7 @@ class TestTerminal:
"*test_pass_skip_fail_verbose.py:4: *test_skip*SKIP*",
"*test_pass_skip_fail_verbose.py:6: *test_func*FAIL*",
])
rep.config.hook.pytest_testrunfinish(exitstatus=1)
rep.config.hook.pytest_sessionfinish(session=testdir.session, exitstatus=1)
linecomp.assert_contains_lines([
" def test_func():",
"> assert 0",
@ -461,13 +461,13 @@ class TestTerminal:
modcol = testdir.getmodulecol("import xyz")
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
rep.config.pluginmanager.register(rep)
rep.config.hook.pytest_testrunstart()
rep.config.hook.pytest_sessionstart(session=testdir.session)
l = list(testdir.genitems([modcol]))
assert len(l) == 0
linecomp.assert_contains_lines([
"*test_collect_fail.py F*"
])
rep.config.hook.pytest_testrunfinish(exitstatus=1)
rep.config.hook.pytest_sessionfinish(session=testdir.session, exitstatus=1)
linecomp.assert_contains_lines([
"> import xyz",
"E ImportError: No module named xyz"
@ -557,11 +557,11 @@ class TestTerminal:
""", configargs=("--tb=%s" % tbopt,))
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
rep.config.pluginmanager.register(rep)
rep.config.hook.pytest_testrunstart()
rep.config.hook.pytest_sessionstart(session=testdir.session)
for item in testdir.genitems([modcol]):
rep.config.hook.pytest_itemtestreport(
rep=runner.basic_run_report(item))
rep.config.hook.pytest_testrunfinish(exitstatus=1)
rep.config.hook.pytest_sessionfinish(session=testdir.session, exitstatus=1)
s = linecomp.stringio.getvalue()
if tbopt == "long":
print s
@ -637,7 +637,7 @@ class TestTerminal:
#""", configargs=("--showskipsummary",) + ("-v",)*verbose)
rep = TerminalReporter(modcol.config, file=linecomp.stringio)
modcol.config.pluginmanager.register(rep)
modcol.config.hook.pytest_testrunstart()
modcol.config.hook.pytest_sessionstart(session=testdir.session)
try:
for item in testdir.genitems([modcol]):
modcol.config.hook.pytest_itemtestreport(
@ -649,7 +649,8 @@ class TestTerminal:
s = linecomp.stringio.getvalue()
if not verbose:
assert s.find("_keyboard_interrupt.py Fs") != -1
modcol.config.hook.pytest_testrunfinish(exitstatus=2, excrepr=excinfo.getrepr())
modcol.config.hook.pytest_sessionfinish(
session=testdir.session, exitstatus=2, excrepr=excinfo.getrepr())
text = linecomp.stringio.getvalue()
linecomp.assert_contains_lines([
" def test_foobar():",

View File

@ -78,7 +78,7 @@ class Session(object):
def sessionstarts(self):
""" setup any neccessary resources ahead of the test run. """
self.config.hook.pytest_testrunstart()
self.config.hook.pytest_sessionstart(session=self)
def pytest_itemtestreport(self, rep):
if rep.failed:
@ -89,7 +89,8 @@ class Session(object):
def sessionfinishes(self, exitstatus=0, excinfo=None):
""" teardown any resources after a test run. """
self.config.hook.pytest_testrunfinish(
self.config.hook.pytest_sessionfinish(
session=self,
exitstatus=exitstatus,
excrepr=excinfo and excinfo.getrepr() or None
)