* streamline hookrecording and global py._com.comregistry patching

* this fixes a reporting bug where events from inner test runs would
  mix with the outer test run

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-05-21 09:45:43 +02:00
parent dcee9bdd6e
commit a58292b473
7 changed files with 41 additions and 21 deletions

View File

@ -101,7 +101,7 @@ class Hooks:
def __init__(self, hookspecs, registry=None):
self._hookspecs = hookspecs
if registry is None:
registry = comregistry
registry = py._com.comregistry
self.registry = registry
for name, method in vars(hookspecs).items():
if name[:2] != "__":

View File

@ -117,6 +117,7 @@ class pytest_funcarg__mysetup:
tmp = request.config.mktemp(request.function.__name__, numbered=True)
self.source = tmp.mkdir("source")
self.dest = tmp.mkdir("dest")
request.getfuncargvalue("_pytest") # to have patching of py._com.comregistry
class TestHRSync:
def test_hrsync_filter(self, mysetup):

View File

@ -174,7 +174,7 @@ class TestDSession:
session.senditems_load([item1, item2])
node = session.item2nodes[item1] [0]
session.queueevent("pytest_testnodedown", node=node, error=None)
reprec = testdir.getreportrecorder(session.pluginmanager)
reprec = testdir.getreportrecorder(session)
print session.item2nodes
loopstate = session._initloopstate([])
session.loop_once(loopstate)
@ -261,7 +261,7 @@ class TestDSession:
session.addnode(node)
loopstate = session._initloopstate([])
loopstate.shuttingdown = True
reprec = testdir.getreportrecorder(session.pluginmanager)
reprec = testdir.getreportrecorder(session)
session.queueevent("pytest_itemtestreport", rep=run(item, node))
session.loop_once(loopstate)
assert not reprec.getcalls("pytest_testnodedown")
@ -282,7 +282,7 @@ class TestDSession:
dsel = session.filteritems([modcol])
assert dsel == [modcol]
items = modcol.collect()
hookrecorder = testdir.getreportrecorder(session.pluginmanager).hookrecorder
hookrecorder = testdir.getreportrecorder(session).hookrecorder
remaining = session.filteritems(items)
assert remaining == []
@ -354,7 +354,7 @@ class TestDSession:
""")
config = testdir.parseconfig('-d', p1, '--tx=popen')
dsession = DSession(config)
hookrecorder = testdir.getreportrecorder(config.pluginmanager).hookrecorder
hookrecorder = testdir.getreportrecorder(config).hookrecorder
dsession.main([config.getfsnode(p1)])
rep = hookrecorder.popcall("pytest_itemtestreport").rep
assert rep.passed

View File

@ -8,6 +8,7 @@ class pytest_funcarg__mysetup:
numbered=True)
self.source = basetemp.mkdir("source")
self.dest = basetemp.mkdir("dest")
request.getfuncargvalue("_pytest")
class TestNodeManager:
@py.test.mark.xfail("consider / forbid implicit rsyncdirs?")
@ -107,7 +108,7 @@ class TestNodeManager:
config = py.test.config._reparse([source, '--debug'])
assert config.option.debug
nodemanager = NodeManager(config, specs)
sorter = testdir.getreportrecorder(config.pluginmanager).hookrecorder
sorter = testdir.getreportrecorder(config).hookrecorder
nodemanager.setup_nodes(putevent=[].append)
for spec in nodemanager.gwmanager.specs:
l = sorter.getcalls("pytest_trace")

View File

@ -6,11 +6,15 @@ def pytest_funcarg___pytest(request):
class PytestArg:
def __init__(self, request):
self.request = request
self.monkeypatch = self.request.getfuncargvalue("monkeypatch")
self.comregistry = py._com.Registry()
self.monkeypatch.setattr(py._com, 'comregistry', self.comregistry)
def gethookrecorder(self, hookspecs, comregistry=None):
if comregistry is None:
comregistry = self.request.config.pluginmanager.comregistry
hookrecorder = HookRecorder(comregistry)
def gethookrecorder(self, hookspecs, registry=None):
if registry is not None:
self.monkeypatch.setattr(py._com, 'comregistry', registry)
self.comregistry = registry
hookrecorder = HookRecorder(self.comregistry)
hookrecorder.start_recording(hookspecs)
self.request.addfinalizer(hookrecorder.finish_recording)
return hookrecorder
@ -111,6 +115,11 @@ def test_hookrecorder_basic():
assert call._name == "xyz"
py.test.raises(ValueError, "rec.popcall('abc')")
reg = py._com.comregistry
def test_functional_default(testdir, _pytest):
assert _pytest.comregistry == py._com.comregistry
assert _pytest.comregistry != reg
def test_functional(testdir, linecomp):
sorter = testdir.inline_runsource("""
import py

View File

@ -7,7 +7,6 @@ import os
import inspect
from py.__.test import runner
from py.__.test.config import Config as pytestConfig
from pytest__pytest import HookRecorder
import api
@ -40,6 +39,7 @@ class RunResult:
class TmpTestdir:
def __init__(self, request):
self.request = request
self._pytest = request.getfuncargvalue("_pytest")
# XXX remove duplication with tmpdir plugin
basetmp = request.config.ensuretemp("testdir")
name = request.function.__name__
@ -73,13 +73,22 @@ class TmpTestdir:
if hasattr(self, '_olddir'):
self._olddir.chdir()
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 getreportrecorder(self, obj):
if isinstance(obj, py._com.Registry):
registry = obj
elif hasattr(obj, 'comregistry'):
registry = obj.comregistry
elif hasattr(obj, 'pluginmanager'):
registry = obj.pluginmanager.comregistry
elif hasattr(obj, 'config'):
registry = obj.config.pluginmanager.comregistry
else:
raise ValueError("obj %r provides no comregistry" %(obj,))
assert isinstance(registry, py._com.Registry)
reprec = ReportRecorder(registry)
reprec.hookrecorder = self._pytest.gethookrecorder(api.PluginHooks, registry)
reprec.hook = reprec.hookrecorder.hook
return reprec
def chdir(self):
old = self.tmpdir.chdir()
@ -130,7 +139,7 @@ class TmpTestdir:
#config = self.parseconfig(*args)
config = self.parseconfig(*args)
session = config.initsession()
rec = self.getreportrecorder(config.pluginmanager)
rec = self.getreportrecorder(config)
colitems = [config.getfsnode(arg) for arg in config.args]
items = list(session.genitems(colitems))
return items, rec
@ -152,7 +161,7 @@ class TmpTestdir:
config = self.parseconfig(*args)
config.pluginmanager.do_configure(config)
session = config.initsession()
sorter = self.getreportrecorder(config.pluginmanager)
sorter = self.getreportrecorder(config)
session.main()
config.pluginmanager.do_unconfigure(config)
return sorter

View File

@ -208,7 +208,7 @@ class TestRunnerPlugin:
item = testdir.getitem("""def test_func(): pass""")
plugin = RunnerPlugin()
plugin.pytest_configure(item.config)
sorter = testdir.getreportrecorder(item.config.pluginmanager)
sorter = testdir.getreportrecorder(item)
plugin.pytest_item_setup_and_runtest(item)
rep = sorter.getcall("pytest_itemtestreport").rep
assert rep.passed