From 2dd3ea7041afa62cc6fe7b462eb7eeca80aedd7c Mon Sep 17 00:00:00 2001 From: hpk Date: Thu, 9 Apr 2009 01:50:02 +0200 Subject: [PATCH] [svn r63886] another few events --HG-- branch : trunk --- py/test/dist/dsession.py | 6 +++--- py/test/dist/testing/test_dsession.py | 13 ++++++------- py/test/looponfail/remote.py | 2 +- py/test/plugin/api.py | 17 ++++++++--------- py/test/plugin/pytest_terminal.py | 6 +++--- py/test/session.py | 2 +- py/test/testing/test_genitems.py | 4 ++-- 7 files changed, 24 insertions(+), 26 deletions(-) diff --git a/py/test/dist/dsession.py b/py/test/dist/dsession.py index cc6e5dd8a..3d91b11f1 100644 --- a/py/test/dist/dsession.py +++ b/py/test/dist/dsession.py @@ -44,7 +44,7 @@ class LoopState(object): self.dsession.handle_crashitem(crashitem, node) self.colitems.extend(pending[1:]) - def pyevent__rescheduleitems(self, items): + def pytest_rescheduleitems(self, items): self.colitems.extend(items) self.dowork = False # avoid busywait @@ -204,7 +204,7 @@ class DSession(Session): tosend[:] = tosend[room:] # update inplace if tosend: # we have some left, give it to the main loop - self.queueevent("rescheduleitems", tosend) + self.queueevent(pytest_rescheduleitems, tosend) def senditems_load(self, tosend): if not tosend: @@ -226,7 +226,7 @@ class DSession(Session): break if tosend: # we have some left, give it to the main loop - self.queueevent("rescheduleitems", tosend) + self.queueevent("pytest_rescheduleitems", items=tosend) def removeitem(self, item, node): if item not in self.item2nodes: diff --git a/py/test/dist/testing/test_dsession.py b/py/test/dist/testing/test_dsession.py index bbf29c7a1..cf2d05796 100644 --- a/py/test/dist/testing/test_dsession.py +++ b/py/test/dist/testing/test_dsession.py @@ -99,9 +99,8 @@ class TestDSession: assert session.node2pending[node1] == sent1 assert session.node2pending[node2] == sent2 name, args, kwargs = session.queue.get(block=False) - assert name == "rescheduleitems" - items, = args - assert items == [item] + assert name == "pytest_rescheduleitems" + assert kwargs['items'] == [item] def test_keyboardinterrupt(self, testdir): item = testdir.getitem("def test_func(): pass") @@ -125,7 +124,7 @@ class TestDSession: node = MockNode() session.addnode(node) loopstate = session._initloopstate([]) - session.queueevent("rescheduleitems", [item]) + session.queueevent("pytest_rescheduleitems", items=[item]) session.loop_once(loopstate) # check that RescheduleEvents are not immediately # rescheduled if there are no nodes @@ -292,18 +291,18 @@ class TestDSession: dsel = session.filteritems([modcol]) assert dsel == [modcol] items = modcol.collect() - evrec = testdir.geteventrecorder(session.bus) + callrecorder = testdir.geteventrecorder(session.bus).callrecorder remaining = session.filteritems(items) assert remaining == [] - event = evrec.getcalls("deselected")[-1] + event = callrecorder.getcalls("pytest_deselected")[-1] assert event.items == items modcol.config.option.keyword = "test_fail" remaining = session.filteritems(items) assert remaining == [items[0]] - event = evrec.getcalls("deselected")[-1] + event = callrecorder.getcalls("pytest_deselected")[-1] assert event.items == [items[1]] def test_testnodedown_shutdown_after_completion(self, testdir): diff --git a/py/test/looponfail/remote.py b/py/test/looponfail/remote.py index 2b23fdbd2..d07da54fd 100644 --- a/py/test/looponfail/remote.py +++ b/py/test/looponfail/remote.py @@ -147,7 +147,7 @@ def slave_runsession(channel, config, fullwidth, hasmarkup): DEBUG("SLAVE: starting session.main()") session.main(colitems) - session.bus.notify("looponfailinfo", + session.config.api.pytest_looponfailinfo( failreports=list(failreports), rootdirs=[config.topdir]) channel.send([x.colitem._totrail() for x in failreports]) diff --git a/py/test/plugin/api.py b/py/test/plugin/api.py index e1a14e543..d5a7eb836 100644 --- a/py/test/plugin/api.py +++ b/py/test/plugin/api.py @@ -104,6 +104,14 @@ class PluginHooks: def pytest_testrunfinish(self, exitstatus, excrepr=None): """ whole test run finishes. """ + def pytest_deselected(self, items): + """ collected items that were deselected (by keyword). """ + + def pytest_rescheduleitems(self, items): + """ reschedule Items from a node that went down. """ + + def pytest_looponfailinfo(self, failreports, rootdirs): + """ info for repeating failing tests. """ class Events: @@ -120,13 +128,4 @@ class Events: def pyevent__internalerror(self, excrepr): """ called for internal errors. """ - def pyevent__deselected(self, items): - """ collected items that were deselected (by keyword). """ - - def pytest_rescheduleitems(self, items): - """ reschedule Items from a node that went down. """ - - def pyevent__looponfailinfo(self, failreports, rootdirs): - """ info for repeating failing tests. """ - diff --git a/py/test/plugin/pytest_terminal.py b/py/test/plugin/pytest_terminal.py index 3b9200263..70cd26e2b 100644 --- a/py/test/plugin/pytest_terminal.py +++ b/py/test/plugin/pytest_terminal.py @@ -158,7 +158,7 @@ class TerminalReporter: if self.config.option.debug: self.write_sep("!", "RESCHEDULING %s " %(items,)) - def pyevent__deselected(self, items): + def pytest_deselected(self, items): self.stats.setdefault('deselected', []).append(items) def pytest_itemtestreport(self, rep): @@ -232,7 +232,7 @@ class TerminalReporter: self.summary_deselected() self.summary_stats() - def pyevent__looponfailinfo(self, failreports, rootdirs): + def pytest_looponfailinfo(self, failreports, rootdirs): if failreports: self.write_sep("#", "LOOPONFAILING", red=True) for report in failreports: @@ -495,7 +495,7 @@ class TestTerminal: """) rep = TerminalReporter(modcol.config, file=linecomp.stringio) reports = [runner.basic_run_report(x) for x in modcol.collect()] - rep.pyevent__looponfailinfo(reports, [modcol.config.topdir]) + rep.pytest_looponfailinfo(reports, [modcol.config.topdir]) linecomp.assert_contains_lines([ "*test_looponfailreport.py:2: assert 0", "*test_looponfailreport.py:4: ValueError*", diff --git a/py/test/session.py b/py/test/session.py index bd78559e4..70057bb7d 100644 --- a/py/test/session.py +++ b/py/test/session.py @@ -66,7 +66,7 @@ class Session(object): continue remaining.append(colitem) if deselected: - self.bus.notify("deselected", deselected) + self.config.api.pytest_deselected(items=deselected) if self.config.option.keyword.endswith(":"): self._nomatch = True return remaining diff --git a/py/test/testing/test_genitems.py b/py/test/testing/test_genitems.py index 11e7f51e6..a51a79451 100644 --- a/py/test/testing/test_genitems.py +++ b/py/test/testing/test_genitems.py @@ -102,7 +102,7 @@ class TestKeywordSelection: passed, skipped, failed = sorter.listoutcomes() assert len(passed) == 1 assert passed[0].colitem.name == "test_2" - dlist = sorter.getcalls("deselected") + dlist = sorter.getcalls("pytest_deselected") assert len(dlist) == 1 assert dlist[0].items[0].name == 'test_1' @@ -116,7 +116,7 @@ class TestKeywordSelection: passed, skipped, failed = sorter.listoutcomes() assert len(passed) == 2 assert not failed - dlist = sorter.getcalls("deselected") + dlist = sorter.getcalls("pytest_deselected") assert len(dlist) == 1 item = dlist[0].items[0] assert item.name == "test_one"