diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index 3a7cc0489..e1a14e543 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -98,6 +98,13 @@ class PluginHooks: def pytest_testnodedown(self, node, error): """ Test Node is down. """ + def pytest_testrunstart(self): + """ whole test run starts. """ + + def pytest_testrunfinish(self, exitstatus, excrepr=None): + """ whole test run finishes. """ + + class Events: # Events @@ -116,19 +123,6 @@ class Events: def pyevent__deselected(self, items): """ collected items that were deselected (by keyword). """ - - def pyevent__testrunstart(self): - """ whole test run starts. """ - - def pyevent__testrunfinish(self, exitstatus, excrepr=None): - """ whole test run finishes. """ - - def pyevent__gwmanage_newgateway(self, gateway): - """ execnet gateway manager has instantiated a gateway. - The gateway will have an 'id' attribute that is unique - within the gateway manager context. - """ - def pytest_rescheduleitems(self, items): """ reschedule Items from a node that went down. """ diff --git a/py/test/plugin/pytest_execnetcleanup.py b/py/test/plugin/pytest_execnetcleanup.py index 69d6ace1a..889f6c494 100644 --- a/py/test/plugin/pytest_execnetcleanup.py +++ b/py/test/plugin/pytest_execnetcleanup.py @@ -21,11 +21,11 @@ class ExecnetcleanupPlugin: if self._gateways is not None: self._gateways.remove(gateway) - def pyevent__testrunstart(self): + def pytest_testrunstart(self): self.trace("testrunstart") self._gateways = [] - def pyevent__testrunfinish(self, exitstatus, excrepr=None): + def pytest_testrunfinish(self, exitstatus, excrepr=None): self.trace("testrunfinish", exitstatus) l = [] for gw in self._gateways: diff --git a/py/test/plugin/pytest_terminal.py b/py/test/plugin/pytest_terminal.py index 98ec8a251..3b9200263 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -194,7 +194,7 @@ class TerminalReporter: self.stats.setdefault("skipped", []).append(rep) self.write_fspath_result(rep.colitem.fspath, "S") - def pyevent__testrunstart(self): + def pytest_testrunstart(self): self.write_sep("=", "test session starts", bold=True) self._sessionstarttime = py.std.time.time() @@ -219,7 +219,7 @@ class TerminalReporter: for i, testarg in py.builtin.enumerate(self.config.args): self.write_line("test object %d: %s" %(i+1, testarg)) - def pyevent__testrunfinish(self, exitstatus, excrepr=None): + def pytest_testrunfinish(self, exitstatus, excrepr=None): self._tw.line("") if exitstatus in (0, 1, 2): self.summary_failures() @@ -322,7 +322,7 @@ class CollectonlyReporter: self._failed.append(rep) self.indent = self.indent[:-len(self.INDENT)] - def pyevent__testrunfinish(self, exitstatus, excrepr=None): + def pytest_testrunfinish(self, exitstatus, excrepr=None): if self._failed: self.out.sep("!", "collection failures") for rep in self._failed: @@ -369,7 +369,7 @@ class TestTerminal: """) rep = TerminalReporter(modcol.config, file=linecomp.stringio) rep.config.bus.register(rep) - rep.config.bus.notify("testrunstart") + rep.config.api.pytest_testrunstart() for item in testdir.genitems([modcol]): ev = runner.basic_run_report(item) @@ -377,7 +377,7 @@ class TestTerminal: linecomp.assert_contains_lines([ "*test_pass_skip_fail.py .sF" ]) - rep.config.bus.notify("testrunfinish", exitstatus=1) + rep.config.api.pytest_testrunfinish(exitstatus=1) linecomp.assert_contains_lines([ " def test_func():", "> assert 0", @@ -396,7 +396,7 @@ class TestTerminal: """, configargs=("-v",)) rep = TerminalReporter(modcol.config, file=linecomp.stringio) rep.config.bus.register(rep) - rep.config.bus.notify("testrunstart") + rep.config.api.pytest_testrunstart() items = modcol.collect() rep.config.option.debug = True # for item in items: @@ -410,7 +410,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.bus.notify("testrunfinish", exitstatus=1) + rep.config.api.pytest_testrunfinish(exitstatus=1) linecomp.assert_contains_lines([ " def test_func():", "> assert 0", @@ -421,13 +421,13 @@ class TestTerminal: modcol = testdir.getmodulecol("import xyz") rep = TerminalReporter(modcol.config, file=linecomp.stringio) rep.config.bus.register(rep) - rep.config.bus.notify("testrunstart") + rep.config.api.pytest_testrunstart() l = list(testdir.genitems([modcol])) assert len(l) == 0 linecomp.assert_contains_lines([ "*test_collect_fail.py F*" ]) - rep.config.bus.notify("testrunfinish", exitstatus=1) + rep.config.api.pytest_testrunfinish(exitstatus=1) linecomp.assert_contains_lines([ "> import xyz", "E ImportError: No module named xyz" @@ -517,12 +517,11 @@ class TestTerminal: """, configargs=("--tb=%s" % tbopt,)) rep = TerminalReporter(modcol.config, file=linecomp.stringio) rep.config.bus.register(rep) - rep.config.bus.notify("testrunstart") - rep.config.bus.notify("testrunstart") + rep.config.api.pytest_testrunstart() for item in testdir.genitems([modcol]): rep.config.api.pytest_itemtestreport( rep=runner.basic_run_report(item)) - rep.config.bus.notify("testrunfinish", exitstatus=1) + rep.config.api.pytest_testrunfinish(exitstatus=1) s = linecomp.stringio.getvalue() if tbopt == "long": print s @@ -566,7 +565,7 @@ class TestTerminal: rep = TerminalReporter(modcol.config, file=linecomp.stringio) modcol.config.bus.register(rep) bus = modcol.config.bus - bus.notify("testrunstart") + modcol.config.api.pytest_testrunstart() try: for item in testdir.genitems([modcol]): modcol.config.api.pytest_itemtestreport( @@ -578,7 +577,7 @@ class TestTerminal: s = linecomp.stringio.getvalue() if not verbose: assert s.find("_keyboard_interrupt.py Fs") != -1 - bus.notify("testrunfinish", exitstatus=2, excrepr=excinfo.getrepr()) + modcol.config.api.pytest_testrunfinish(exitstatus=2, excrepr=excinfo.getrepr()) text = linecomp.stringio.getvalue() linecomp.assert_contains_lines([ " def test_foobar():", diff --git a/py/test/session.py b/py/test/session.py index c8824ea43..bd78559e4 100644 --- a/py/test/session.py +++ b/py/test/session.py @@ -78,7 +78,7 @@ class Session(object): def sessionstarts(self): """ setup any neccessary resources ahead of the test run. """ - self.bus.notify("testrunstart") + self.config.api.pytest_testrunstart() def pytest_itemtestreport(self, rep): if rep.failed: @@ -89,9 +89,10 @@ class Session(object): def sessionfinishes(self, exitstatus=0, excinfo=None): """ teardown any resources after a test run. """ - self.bus.notify("testrunfinish", - exitstatus=exitstatus, - excrepr=excinfo and excinfo.getrepr() or None) + self.config.api.pytest_testrunfinish( + exitstatus=exitstatus, + excrepr=excinfo and excinfo.getrepr() or None + ) def getinitialitems(self, colitems): if colitems is None: