From 1973817f1173dadb86c3856ba98cc283d134d2b0 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 19 May 2009 19:25:21 +0200 Subject: [PATCH] rename recorder functionality, unify interfaces --HG-- branch : trunk --- py/execnet/testing/test_event.py | 2 +- py/execnet/testing/test_gwmanage.py | 4 +- py/test/dist/testing/test_dsession.py | 26 +++--- py/test/dist/testing/test_nodemanage.py | 2 +- py/test/plugin/pytest__pytest.py | 50 +++++------ py/test/plugin/pytest_doctest.py | 2 +- py/test/plugin/pytest_iocapture.py | 8 +- py/test/plugin/pytest_pocoo.py | 4 +- py/test/plugin/pytest_pytester.py | 108 ++++++++--------------- py/test/plugin/pytest_runner.py | 4 +- py/test/pluginmanager.py | 28 +++--- py/test/testing/test_collect.py | 8 +- py/test/testing/test_genitems.py | 2 +- py/test/testing/test_pluginmanager.py | 17 +++- py/test/testing/test_runner.py | 24 ++--- py/test/testing/test_session.py | 12 +-- py/test/testing/test_setup_functional.py | 2 +- 17 files changed, 146 insertions(+), 157 deletions(-) diff --git a/py/execnet/testing/test_event.py b/py/execnet/testing/test_event.py index 27da49141..cbdc86a10 100644 --- a/py/execnet/testing/test_event.py +++ b/py/execnet/testing/test_event.py @@ -4,7 +4,7 @@ from py.__.execnet.gateway import ExecnetAPI class TestExecnetEvents: def test_popengateway(self, _pytest): - rec = _pytest.getcallrecorder(ExecnetAPI) + rec = _pytest.gethookrecorder(ExecnetAPI) gw = py.execnet.PopenGateway() call = rec.popcall("pyexecnet_gateway_init") assert call.gateway == gw diff --git a/py/execnet/testing/test_gwmanage.py b/py/execnet/testing/test_gwmanage.py index 5ebcfceaa..8940ab55a 100644 --- a/py/execnet/testing/test_gwmanage.py +++ b/py/execnet/testing/test_gwmanage.py @@ -21,7 +21,7 @@ class TestGatewayManagerPopen: assert spec.chdir == "abc" def test_popen_makegateway_events(self, _pytest): - rec = _pytest.getcallrecorder(py.execnet._HookSpecs) + rec = _pytest.gethookrecorder(py.execnet._HookSpecs) hm = GatewayManager(["popen"] * 2) hm.makegateways() call = rec.popcall("pyexecnet_gwmanage_newgateway") @@ -63,7 +63,7 @@ class TestGatewayManagerPopen: def test_hostmanage_rsync_same_popen_twice(self, mysetup, _pytest): source, dest = mysetup.source, mysetup.dest - rec = _pytest.getcallrecorder(py.execnet._HookSpecs) + rec = _pytest.gethookrecorder(py.execnet._HookSpecs) hm = GatewayManager(["popen//chdir=%s" %dest] * 2) hm.makegateways() source.ensure("dir1", "dir2", "hello") diff --git a/py/test/dist/testing/test_dsession.py b/py/test/dist/testing/test_dsession.py index 1ffdea351..dc5fadc30 100644 --- a/py/test/dist/testing/test_dsession.py +++ b/py/test/dist/testing/test_dsession.py @@ -174,13 +174,13 @@ class TestDSession: session.senditems_load([item1, item2]) node = session.item2nodes[item1] [0] session.queueevent("pytest_testnodedown", node=node, error=None) - evrec = testdir.geteventrecorder(session.pluginmanager) + reprec = testdir.getreportrecorder(session.pluginmanager) print session.item2nodes loopstate = session._initloopstate([]) session.loop_once(loopstate) assert loopstate.colitems == [item2] # do not reschedule crash item - testrep = evrec.matchreport(names="itemtestreport") + testrep = reprec.matchreport(names="pytest_itemtestreport") assert testrep.failed assert testrep.colitem == item1 assert str(testrep.longrepr).find("crashed") != -1 @@ -261,13 +261,13 @@ class TestDSession: session.addnode(node) loopstate = session._initloopstate([]) loopstate.shuttingdown = True - evrec = testdir.geteventrecorder(session.pluginmanager) + reprec = testdir.getreportrecorder(session.pluginmanager) session.queueevent("pytest_itemtestreport", rep=run(item, node)) session.loop_once(loopstate) - assert not evrec.getcalls("pytest_testnodedown") + assert not reprec.getcalls("pytest_testnodedown") session.queueevent("pytest_testnodedown", node=node, error=None) session.loop_once(loopstate) - assert evrec.getcall('pytest_testnodedown').node == node + assert reprec.getcall('pytest_testnodedown').node == node def test_filteritems(self, testdir): modcol = testdir.getmodulecol(""" @@ -282,18 +282,18 @@ class TestDSession: dsel = session.filteritems([modcol]) assert dsel == [modcol] items = modcol.collect() - callrecorder = testdir.geteventrecorder(session.pluginmanager).callrecorder + hookrecorder = testdir.getreportrecorder(session.pluginmanager).hookrecorder remaining = session.filteritems(items) assert remaining == [] - event = callrecorder.getcalls("pytest_deselected")[-1] + event = hookrecorder.getcalls("pytest_deselected")[-1] assert event.items == items modcol.config.option.keyword = "test_fail" remaining = session.filteritems(items) assert remaining == [items[0]] - event = callrecorder.getcalls("pytest_deselected")[-1] + event = hookrecorder.getcalls("pytest_deselected")[-1] assert event.items == [items[1]] def test_testnodedown_shutdown_after_completion(self, testdir): @@ -355,16 +355,16 @@ class TestDSession: """) config = testdir.parseconfig('-d', p1, '--tx=popen') dsession = DSession(config) - callrecorder = testdir.geteventrecorder(config.pluginmanager).callrecorder + hookrecorder = testdir.getreportrecorder(config.pluginmanager).hookrecorder dsession.main([config.getfsnode(p1)]) - rep = callrecorder.popcall("pytest_itemtestreport").rep + rep = hookrecorder.popcall("pytest_itemtestreport").rep assert rep.passed - rep = callrecorder.popcall("pytest_itemtestreport").rep + rep = hookrecorder.popcall("pytest_itemtestreport").rep assert rep.skipped - rep = callrecorder.popcall("pytest_itemtestreport").rep + rep = hookrecorder.popcall("pytest_itemtestreport").rep assert rep.failed # see that the node is really down - node = callrecorder.popcall("pytest_testnodedown").node + node = hookrecorder.popcall("pytest_testnodedown").node assert node.gateway.spec.popen #XXX eq.geteventargs("pytest_testrunfinish") diff --git a/py/test/dist/testing/test_nodemanage.py b/py/test/dist/testing/test_nodemanage.py index f29edba58..f4e554d8a 100644 --- a/py/test/dist/testing/test_nodemanage.py +++ b/py/test/dist/testing/test_nodemanage.py @@ -107,7 +107,7 @@ class TestNodeManager: config = py.test.config._reparse([source, '--debug']) assert config.option.debug nodemanager = NodeManager(config, specs) - sorter = testdir.geteventrecorder(config.pluginmanager).callrecorder + sorter = testdir.getreportrecorder(config.pluginmanager).hookrecorder nodemanager.setup_nodes(putevent=[].append) for spec in nodemanager.gwmanager.specs: l = sorter.getcalls("pytest_trace") diff --git a/py/test/plugin/pytest__pytest.py b/py/test/plugin/pytest__pytest.py index 0aa15ead7..4959c7b41 100644 --- a/py/test/plugin/pytest__pytest.py +++ b/py/test/plugin/pytest__pytest.py @@ -7,14 +7,13 @@ class PytestArg: def __init__(self, request): self.request = request - def getcallrecorder(self, hookspecs, comregistry=None): + def gethookrecorder(self, hookspecs, comregistry=None): if comregistry is None: comregistry = self.request.config.pluginmanager.comregistry - callrecorder = CallRecorder(comregistry) - callrecorder.start_recording(hookspecs) - self.request.addfinalizer(callrecorder.finalize) - return callrecorder - + hookrecorder = HookRecorder(comregistry) + hookrecorder.start_recording(hookspecs) + self.request.addfinalizer(hookrecorder.finish_recording) + return hookrecorder class ParsedCall: def __init__(self, name, locals): @@ -28,7 +27,7 @@ class ParsedCall: del d['_name'] return "" %(self._name, d) -class CallRecorder: +class HookRecorder: def __init__(self, comregistry): self._comregistry = comregistry self.calls = [] @@ -40,23 +39,18 @@ class CallRecorder: _recorder = self for name, method in vars(hookspecs).items(): if name[0] != "_": - setattr(RecordCalls, name, self._getcallparser(method)) + setattr(RecordCalls, name, self._makecallparser(method)) recorder = RecordCalls() self._recorders[hookspecs] = recorder self._comregistry.register(recorder) self.hook = py._com.Hooks(hookspecs, registry=self._comregistry) - def finalize(self): + def finish_recording(self): for recorder in self._recorders.values(): self._comregistry.unregister(recorder) self._recorders.clear() - def recordsmethod(self, name): - for hookspecs in self._recorders: - if hasattr(hookspecs, name): - return True - - def _getcallparser(self, method): + def _makecallparser(self, method): name = method.__name__ args, varargs, varkw, default = py.std.inspect.getargspec(method) assert args[0] == "self" @@ -72,13 +66,6 @@ class CallRecorder: """ % locals()) return locals()[name] - def popcall(self, name): - for i, call in py.builtin.enumerate(self.calls): - if call._name == name: - del self.calls[i] - return call - raise ValueError("could not find call %r in %r" %(name, self.calls)) - def getcalls(self, names): if isinstance(names, str): names = names.split() @@ -95,12 +82,25 @@ class CallRecorder: l.append(call) return l + def popcall(self, name): + for i, call in py.builtin.enumerate(self.calls): + if call._name == name: + del self.calls[i] + return call + raise ValueError("could not find call %r in %r" %(name, self.calls)) + + def getcall(self, name): + l = self.getcalls(name) + assert len(l) == 1, (name, l) + return l[0] + + def test_generic(plugintester): plugintester.hookcheck() -def test_callrecorder_basic(): +def test_hookrecorder_basic(): comregistry = py._com.Registry() - rec = CallRecorder(comregistry) + rec = HookRecorder(comregistry) class ApiClass: def xyz(self, arg): pass @@ -118,7 +118,7 @@ def test_functional(testdir, linecomp): def test_func(_pytest): class ApiClass: def xyz(self, arg): pass - rec = _pytest.getcallrecorder(ApiClass) + rec = _pytest.gethookrecorder(ApiClass) class Plugin: def xyz(self, arg): return arg + 1 diff --git a/py/test/plugin/pytest_doctest.py b/py/test/plugin/pytest_doctest.py index 17cdb2d8a..c97e89749 100644 --- a/py/test/plugin/pytest_doctest.py +++ b/py/test/plugin/pytest_doctest.py @@ -93,7 +93,7 @@ class TestDoctests: def test_collect_module(self, testdir): path = testdir.makepyfile(whatever="#") for p in (path, testdir.tmpdir): - items, evrec = testdir.inline_genitems(p, '--doctest-modules') + items, reprec = testdir.inline_genitems(p, '--doctest-modules') assert len(items) == 1 assert isinstance(items[0], DoctestModule) diff --git a/py/test/plugin/pytest_iocapture.py b/py/test/plugin/pytest_iocapture.py index 16106866e..32221ed0d 100644 --- a/py/test/plugin/pytest_iocapture.py +++ b/py/test/plugin/pytest_iocapture.py @@ -30,20 +30,20 @@ def test_generic(plugintester): class TestCapture: def test_std_functional(self, testdir): - evrec = testdir.inline_runsource(""" + reprec = testdir.inline_runsource(""" def test_hello(stdcapture): print 42 out, err = stdcapture.reset() assert out.startswith("42") """) - evrec.assertoutcome(passed=1) + reprec.assertoutcome(passed=1) def test_stdfd_functional(self, testdir): - evrec = testdir.inline_runsource(""" + reprec = testdir.inline_runsource(""" def test_hello(stdcapturefd): import os os.write(1, "42") out, err = stdcapturefd.reset() assert out.startswith("42") """) - evrec.assertoutcome(passed=1) + reprec.assertoutcome(passed=1) diff --git a/py/test/plugin/pytest_pocoo.py b/py/test/plugin/pytest_pocoo.py index b4bf1bae2..9959b3179 100644 --- a/py/test/plugin/pytest_pocoo.py +++ b/py/test/plugin/pytest_pocoo.py @@ -57,10 +57,10 @@ def test_toproxy(testdir, monkeypatch): def test_skip(): py.test.skip("") """) - evrec = testdir.inline_run(testpath, "-P") + reprec = testdir.inline_run(testpath, "-P") assert len(l) == 1 assert l[0][0] == "python" s = l[0][1] assert s.find("def test_fail") != -1 - assert evrec.countoutcomes() == [1,1,1] + assert reprec.countoutcomes() == [1,1,1] diff --git a/py/test/plugin/pytest_pytester.py b/py/test/plugin/pytest_pytester.py index 4d52d42c4..7794fe579 100644 --- a/py/test/plugin/pytest_pytester.py +++ b/py/test/plugin/pytest_pytester.py @@ -7,9 +7,10 @@ import os import inspect from py.__.test import runner from py.__.test.config import Config as pytestConfig -from pytest__pytest import CallRecorder +from pytest__pytest import HookRecorder import api + def pytest_funcarg__linecomp(request): return LineComp() @@ -20,10 +21,10 @@ def pytest_funcarg__testdir(request): tmptestdir = TmpTestdir(request) return tmptestdir -def pytest_funcarg__eventrecorder(request): - evrec = EventRecorder(py._com.comregistry) - request.addfinalizer(lambda: evrec.comregistry.unregister(evrec)) - return evrec +def pytest_funcarg__reportrecorder(request): + reprec = ReportRecorder(py._com.comregistry) + request.addfinalizer(lambda: reprec.comregistry.unregister(reprec)) + return reprec def test_generic(plugintester): plugintester.hookcheck() @@ -72,12 +73,12 @@ class TmpTestdir: if hasattr(self, '_olddir'): self._olddir.chdir() - def geteventrecorder(self, registry): - sorter = EventRecorder(registry) - sorter.callrecorder = CallRecorder(registry) - sorter.callrecorder.start_recording(api.PluginHooks) - sorter.hook = sorter.callrecorder.hook - self.request.addfinalizer(sorter.callrecorder.finalize) + def getreportrecorder(self, registry): + sorter = ReportRecorder(registry) + sorter.hookrecorder = HookRecorder(registry) + sorter.hookrecorder.start_recording(api.PluginHooks) + sorter.hook = sorter.hookrecorder.hook + self.request.addfinalizer(sorter.hookrecorder.finish_recording) return sorter def chdir(self): @@ -129,7 +130,7 @@ class TmpTestdir: #config = self.parseconfig(*args) config = self.parseconfig(*args) session = config.initsession() - rec = self.geteventrecorder(config.pluginmanager) + rec = self.getreportrecorder(config.pluginmanager) colitems = [config.getfsnode(arg) for arg in config.args] items = list(session.genitems(colitems)) return items, rec @@ -151,7 +152,7 @@ class TmpTestdir: config = self.parseconfig(*args) config.pluginmanager.do_configure(config) session = config.initsession() - sorter = self.geteventrecorder(config.pluginmanager) + sorter = self.getreportrecorder(config.pluginmanager) session.main() config.pluginmanager.do_unconfigure(config) return sorter @@ -161,10 +162,12 @@ class TmpTestdir: for plugin in self.plugins: if isinstance(plugin, str): config.pluginmanager.import_plugin(plugin) - elif plugin: + else: if isinstance(plugin, dict): plugin = PseudoPlugin(plugin) - config.pluginmanager.register(plugin) + if not config.pluginmanager.isregistered(plugin): + config.pluginmanager.register(plugin) + #print "config.pluginmanager.impname2plugin", config.pluginmanager.impname2plugin return config def parseconfig(self, *args): @@ -284,55 +287,24 @@ class PseudoPlugin: def __init__(self, vars): self.__dict__.update(vars) - -class Event: - def __init__(self, name, args, kwargs): - self.name = name - self.args = args - self.kwargs = kwargs - def __repr__(self): - return "" %(self.name, self.args) - -class ParsedCall: - def __init__(self, locals): - self.__dict__ = locals.copy() - - def __repr__(self): - return "" %(self.__dict__,) - -class EventRecorder(object): - def __init__(self, comregistry, debug=False): # True): +class ReportRecorder(object): + def __init__(self, comregistry): self.comregistry = comregistry - self.debug = debug comregistry.register(self) def getcall(self, name): - l = self.getcalls(name) - assert len(l) == 1, (name, l) - return l[0] + return self.hookrecorder.getcall(name) - def getcalls(self, *names): + def getcalls(self, names): """ return list of ParsedCall instances matching the given eventname. """ - if len(names) == 1 and isinstance(names, str): - names = names.split() - l = [] - for name in names: - if self.callrecorder.recordsmethod("pytest_" + name): - name = "pytest_" + name - if self.callrecorder.recordsmethod(name): - l.extend(self.callrecorder.getcalls(name)) - return l + return self.hookrecorder.getcalls(names) # functionality for test reports - def getreports(self, names="itemtestreport collectreport"): - names = [("pytest_" + x) for x in names.split()] - l = [] - for call in self.getcalls(*names): - l.append(call.rep) - return l + def getreports(self, names="pytest_itemtestreport pytest_collectreport"): + return [x.rep for x in self.getcalls(names)] - def matchreport(self, inamepart="", names="itemtestreport collectreport"): + def matchreport(self, inamepart="", names="pytest_itemtestreport pytest_collectreport"): """ return a testreport whose dotted import path matches """ l = [] for rep in self.getreports(names=names): @@ -346,21 +318,17 @@ class EventRecorder(object): inamepart, l)) return l[0] - def getfailures(self, names='itemtestreport collectreport'): - l = [] - for call in self.getcalls(*names.split()): - if call.rep.failed: - l.append(call.rep) - return l + def getfailures(self, names='pytest_itemtestreport pytest_collectreport'): + return [rep for rep in self.getreports(names) if rep.failed] def getfailedcollections(self): - return self.getfailures('collectreport') + return self.getfailures('pytest_collectreport') def listoutcomes(self): passed = [] skipped = [] failed = [] - for rep in self.getreports("itemtestreport"): + for rep in self.getreports("pytest_itemtestreport"): if rep.passed: passed.append(rep) elif rep.skipped: @@ -379,15 +347,15 @@ class EventRecorder(object): assert failed == len(realfailed) def clear(self): - self.callrecorder.calls[:] = [] + self.hookrecorder.calls[:] = [] def unregister(self): self.comregistry.unregister(self) - self.callrecorder.finalize() + self.hookrecorder.finish_recording() -def test_eventrecorder(testdir): +def test_reportrecorder(testdir): registry = py._com.Registry() - recorder = testdir.geteventrecorder(registry) + recorder = testdir.getreportrecorder(registry) assert not recorder.getfailures() rep = runner.ItemTestReport(None, None) rep.passed = False @@ -406,7 +374,7 @@ def test_eventrecorder(testdir): rep = runner.CollectReport(None, None) rep.passed = False rep.failed = True - recorder.hook.pytest_itemtestreport(rep=rep) + recorder.hook.pytest_collectreport(rep=rep) passed, skipped, failed = recorder.listoutcomes() assert not passed and skipped and failed @@ -414,13 +382,13 @@ def test_eventrecorder(testdir): numpassed, numskipped, numfailed = recorder.countoutcomes() assert numpassed == 0 assert numskipped == 1 - assert numfailed == 2 + assert numfailed == 1 + assert len(recorder.getfailedcollections()) == 1 recorder.unregister() recorder.clear() - assert not recorder.getfailures() recorder.hook.pytest_itemtestreport(rep=rep) - assert not recorder.getfailures() + py.test.raises(ValueError, "recorder.getfailures()") class LineComp: def __init__(self): diff --git a/py/test/plugin/pytest_runner.py b/py/test/plugin/pytest_runner.py index c9e54f923..49d38336c 100644 --- a/py/test/plugin/pytest_runner.py +++ b/py/test/plugin/pytest_runner.py @@ -208,7 +208,7 @@ class TestRunnerPlugin: item = testdir.getitem("""def test_func(): pass""") plugin = RunnerPlugin() plugin.pytest_configure(item.config) - sorter = testdir.geteventrecorder(item.config.pluginmanager) + sorter = testdir.getreportrecorder(item.config.pluginmanager) plugin.pytest_item_setup_and_runtest(item) rep = sorter.getcall("pytest_itemtestreport").rep assert rep.passed @@ -248,7 +248,7 @@ class TestSetupEvents: print "13" raise ValueError(25) """) - rep = evrec.popcall(pytest_itemsetupreport).rep + rep = reprec.popcall(pytest_itemsetupreport).rep assert rep.failed assert rep.item == item assert not rep.passed diff --git a/py/test/pluginmanager.py b/py/test/pluginmanager.py index e746a0546..096cd40d7 100644 --- a/py/test/pluginmanager.py +++ b/py/test/pluginmanager.py @@ -20,14 +20,22 @@ class PluginManager(object): hookspecs=api.PluginHooks, registry=self.comregistry) - def register(self, plugin, name=None): + def _getpluginname(self, plugin, name): if name is None: - name = getattr(plugin, '__name__', id(plugin)) - if name not in self.impname2plugin: - self.impname2plugin[name] = plugin - self.hook.pytest_plugin_registered(plugin=plugin) - self.comregistry.register(plugin) - return True + if hasattr(plugin, '__name__'): + name = plugin.__name__.split(".")[-1] + else: + name = id(plugin) + return name + + def register(self, plugin, name=None): + assert not self.isregistered(plugin) + name = self._getpluginname(plugin, name) + assert name not in self.impname2plugin + self.impname2plugin[name] = plugin + self.hook.pytest_plugin_registered(plugin=plugin) + self.comregistry.register(plugin) + return True def unregister(self, plugin): self.hook.pytest_plugin_unregistered(plugin=plugin) @@ -36,8 +44,8 @@ class PluginManager(object): if value == plugin: del self.impname2plugin[name] - def isregistered(self, plugin): - return self.comregistry.isregistered(plugin) + def isregistered(self, plugin, name=None): + return self._getpluginname(plugin, name) in self.impname2plugin def getplugins(self): return list(self.comregistry) @@ -86,7 +94,7 @@ class PluginManager(object): return mod = importplugin(modname) check_old_use(mod, modname) - self.register(mod) + self.register(mod) self.consider_module(mod) # # diff --git a/py/test/testing/test_collect.py b/py/test/testing/test_collect.py index 544df1fa4..93fc3a765 100644 --- a/py/test/testing/test_collect.py +++ b/py/test/testing/test_collect.py @@ -175,7 +175,7 @@ class TestCollectPluginHooks: assert "hello" in wascalled assert "world" in wascalled # make sure the directories do not get double-appended - colreports = sorter.getreports("collectreport") + colreports = sorter.getreports("pytest_collectreport") names = [rep.colitem.name for rep in colreports] assert names.count("hello") == 1 @@ -214,8 +214,8 @@ class TestCustomConftests: """) testdir.mkdir("hello") sorter = testdir.inline_run(testdir.tmpdir) - names = [rep.colitem.name for rep in sorter.getreports("collectreport")] + names = [rep.colitem.name for rep in sorter.getreports("pytest_collectreport")] assert 'hello' not in names - evrec = testdir.inline_run(testdir.tmpdir, "--XX") - names = [rep.colitem.name for rep in evrec.getreports("collectreport")] + reprec = testdir.inline_run(testdir.tmpdir, "--XX") + names = [rep.colitem.name for rep in reprec.getreports("pytest_collectreport")] assert 'hello' in names diff --git a/py/test/testing/test_genitems.py b/py/test/testing/test_genitems.py index 632e54732..6a4251d54 100644 --- a/py/test/testing/test_genitems.py +++ b/py/test/testing/test_genitems.py @@ -74,7 +74,7 @@ class TestKeywordSelection: passed, skipped, failed = sorter.listoutcomes() assert len(failed) == 1 assert failed[0].colitem.name == name - assert len(sorter.getcalls('deselected')) == 1 + assert len(sorter.getcalls('pytest_deselected')) == 1 for keyword in ['test_one', 'est_on']: #yield check, keyword, 'test_one' diff --git a/py/test/testing/test_pluginmanager.py b/py/test/testing/test_pluginmanager.py index d040c2e55..0ca2f5eb0 100644 --- a/py/test/testing/test_pluginmanager.py +++ b/py/test/testing/test_pluginmanager.py @@ -74,7 +74,7 @@ class TestBootstrapping: mod.pytest_plugins = "pytest_a" aplugin = testdir.makepyfile(pytest_a="#") pluginmanager = PluginManager() - sorter = testdir.geteventrecorder(pluginmanager) + sorter = testdir.getreportrecorder(pluginmanager) #syspath.prepend(aplugin.dirpath()) py.std.sys.path.insert(0, str(aplugin.dirpath())) pluginmanager.consider_module(mod) @@ -83,7 +83,7 @@ class TestBootstrapping: # check that it is not registered twice pluginmanager.consider_module(mod) - l = sorter.getcalls("plugin_registered") + l = sorter.getcalls("pytest_plugin_registered") assert len(l) == 1 def test_consider_conftest_deprecated(self, testdir): @@ -113,6 +113,19 @@ class TestBootstrapping: pp.unregister(a2) assert not pp.isregistered(a2) + def test_register_imported_modules(self): + pp = PluginManager() + mod = py.std.new.module("x.y.pytest_hello") + pp.register(mod) + assert pp.isregistered(mod) + assert pp.getplugins() == [mod] + py.test.raises(AssertionError, "pp.register(mod)") + mod2 = py.std.new.module("pytest_hello") + #pp.register(mod2) # double registry + py.test.raises(AssertionError, "pp.register(mod)") + #assert not pp.isregistered(mod2) + assert pp.getplugins() == [mod] # does not actually modify plugins + def test_canonical_importname(self): for name in 'xyz', 'pytest_xyz', 'pytest_Xyz', 'Xyz': impname = canonical_importname(name) diff --git a/py/test/testing/test_runner.py b/py/test/testing/test_runner.py index 7005583db..30953d1ab 100644 --- a/py/test/testing/test_runner.py +++ b/py/test/testing/test_runner.py @@ -19,7 +19,7 @@ class TestSetupStateFunctional: def test_func(): pass """) - evrec = testdir.geteventrecorder(item.config) + reprec = testdir.getreportrecorder(item.config) setup = SetupState() res = setup.do_setup(item) assert res @@ -32,11 +32,11 @@ class TestSetupStateFunctional: def test_func(): pass """) - evrec = testdir.geteventrecorder(item.config) + reprec = testdir.getreportrecorder(item.config) setup = SetupState() res = setup.do_setup(item) assert not res - rep = evrec.popcall(pytest_itemsetupreport).rep + rep = reprec.popcall(pytest_itemsetupreport).rep assert rep.failed assert not rep.skipped assert rep.excrepr @@ -51,14 +51,14 @@ class TestSetupStateFunctional: print "13" raise ValueError(25) """) - evrec = testdir.geteventrecorder(item.config) + reprec = testdir.getreportrecorder(item.config) setup = SetupState() res = setup.do_setup(item) assert res - rep = evrec.popcall(pytest_itemsetupreport).rep + rep = reprec.popcall(pytest_itemsetupreport).rep assert rep.passed setup.do_teardown(item) - rep = evrec.popcall(pytest_itemsetupreport).rep + rep = reprec.popcall(pytest_itemsetupreport).rep assert rep.item == item assert rep.failed assert not rep.passed @@ -73,10 +73,10 @@ class TestSetupStateFunctional: def test_func(): pass """) - evrec = testdir.geteventrecorder(item.config) + reprec = testdir.getreportrecorder(item.config) setup = SetupState() setup.do_setup(item) - rep = evrec.popcall(pytest_itemsetupreport).rep + rep = reprec.popcall(pytest_itemsetupreport).rep assert not rep.failed assert rep.skipped assert rep.excrepr @@ -84,18 +84,18 @@ class TestSetupStateFunctional: def test_runtest_ok(self, testdir): item = testdir.getitem("def test_func(): pass") - evrec = testdir.geteventrecorder(item.config) + reprec = testdir.getreportrecorder(item.config) setup = SetupState() setup.do_fixture_and_runtest(item) - rep = evrec.popcall(pytest_itemtestreport).rep + rep = reprec.popcall(pytest_itemtestreport).rep assert rep.passed def test_runtest_fails(self, testdir): item = testdir.getitem("def test_func(): assert 0") - evrec = testdir.geteventrecorder(item.config) + reprec = testdir.getreportrecorder(item.config) setup = SetupState() setup.do_fixture_and_runtest(item) - event = evrec.popcall(pytest_item_runtest_finished) + event = reprec.popcall(pytest_item_runtest_finished) assert event.excinfo diff --git a/py/test/testing/test_session.py b/py/test/testing/test_session.py index fd2ac3d9a..a62e5d149 100644 --- a/py/test/testing/test_session.py +++ b/py/test/testing/test_session.py @@ -25,9 +25,9 @@ class SessionTests: assert failed[0].colitem.name == "test_one_one" assert failed[1].colitem.name == "test_other" assert failed[2].colitem.name == "test_two" - itemstarted = sorter.getcalls("itemstart") + itemstarted = sorter.getcalls("pytest_itemstart") assert len(itemstarted) == 4 - colstarted = sorter.getcalls("collectstart") + colstarted = sorter.getcalls("pytest_collectstart") assert len(colstarted) == 1 col = colstarted[0].collector assert isinstance(col, py.test.collect.Module) @@ -130,7 +130,7 @@ class SessionTests: def test_one(): pass """) sorter = testdir.inline_run(testdir.tmpdir) - reports = sorter.getreports("collectreport") + reports = sorter.getreports("pytest_collectreport") assert len(reports) == 1 assert reports[0].skipped @@ -201,9 +201,9 @@ class TestNewSession(SessionTests): itemstarted = sorter.getcalls("pytest_itemstart") assert len(itemstarted) == 3 - assert not sorter.getreports("itemtestreport") + assert not sorter.getreports("pytest_itemtestreport") started = sorter.getcalls("pytest_collectstart") - finished = sorter.getreports("collectreport") + finished = sorter.getreports("pytest_collectreport") assert len(started) == len(finished) assert len(started) == 8 colfail = [x for x in finished if x.failed] @@ -215,7 +215,7 @@ class TestNewSession(SessionTests): testdir.makepyfile(__init__="") testdir.makepyfile(test_one="xxxx", test_two="yyyy") sorter = testdir.inline_run("-x", testdir.tmpdir) - finished = sorter.getreports("collectreport") + finished = sorter.getreports("pytest_collectreport") colfail = [x for x in finished if x.failed] assert len(colfail) == 1 diff --git a/py/test/testing/test_setup_functional.py b/py/test/testing/test_setup_functional.py index e0d0a2736..61f9b9bbf 100644 --- a/py/test/testing/test_setup_functional.py +++ b/py/test/testing/test_setup_functional.py @@ -118,7 +118,7 @@ def test_func_generator_setup(testdir): yield check assert x == [1] """) - rep = sorter.matchreport("test_one", names="itemtestreport") + rep = sorter.matchreport("test_one", names="pytest_itemtestreport") assert rep.passed def test_method_setup_uses_fresh_instances(testdir):