some internal fixes regarding the new required hook-finding prefix
--HG-- branch : trunk
This commit is contained in:
parent
fd473d4002
commit
82d4aae571
|
@ -46,7 +46,8 @@ class HookRecorder:
|
||||||
recorder = RecordCalls()
|
recorder = RecordCalls()
|
||||||
self._recorders[hookspec] = recorder
|
self._recorders[hookspec] = recorder
|
||||||
self._registry.register(recorder)
|
self._registry.register(recorder)
|
||||||
self.hook = HookRelay(hookspecs, registry=self._registry)
|
self.hook = HookRelay(hookspecs, registry=self._registry,
|
||||||
|
prefix="pytest_")
|
||||||
|
|
||||||
def finish_recording(self):
|
def finish_recording(self):
|
||||||
for recorder in self._recorders.values():
|
for recorder in self._recorders.values():
|
||||||
|
|
|
@ -6,25 +6,25 @@ from py._test.pluginmanager import Registry
|
||||||
def test_hookrecorder_basic():
|
def test_hookrecorder_basic():
|
||||||
rec = HookRecorder(Registry())
|
rec = HookRecorder(Registry())
|
||||||
class ApiClass:
|
class ApiClass:
|
||||||
def xyz(self, arg):
|
def pytest_xyz(self, arg):
|
||||||
pass
|
"x"
|
||||||
rec.start_recording(ApiClass)
|
rec.start_recording(ApiClass)
|
||||||
rec.hook.xyz(arg=123)
|
rec.hook.pytest_xyz(arg=123)
|
||||||
call = rec.popcall("xyz")
|
call = rec.popcall("pytest_xyz")
|
||||||
assert call.arg == 123
|
assert call.arg == 123
|
||||||
assert call._name == "xyz"
|
assert call._name == "pytest_xyz"
|
||||||
py.test.raises(ValueError, "rec.popcall('abc')")
|
py.test.raises(ValueError, "rec.popcall('abc')")
|
||||||
|
|
||||||
def test_hookrecorder_basic_no_args_hook():
|
def test_hookrecorder_basic_no_args_hook():
|
||||||
rec = HookRecorder(Registry())
|
rec = HookRecorder(Registry())
|
||||||
apimod = type(os)('api')
|
apimod = type(os)('api')
|
||||||
def xyz():
|
def pytest_xyz():
|
||||||
pass
|
"x"
|
||||||
apimod.xyz = xyz
|
apimod.pytest_xyz = pytest_xyz
|
||||||
rec.start_recording(apimod)
|
rec.start_recording(apimod)
|
||||||
rec.hook.xyz()
|
rec.hook.pytest_xyz()
|
||||||
call = rec.popcall("xyz")
|
call = rec.popcall("pytest_xyz")
|
||||||
assert call._name == "xyz"
|
assert call._name == "pytest_xyz"
|
||||||
|
|
||||||
def test_functional(testdir, linecomp):
|
def test_functional(testdir, linecomp):
|
||||||
reprec = testdir.inline_runsource("""
|
reprec = testdir.inline_runsource("""
|
||||||
|
@ -33,14 +33,14 @@ def test_functional(testdir, linecomp):
|
||||||
pytest_plugins="_pytest"
|
pytest_plugins="_pytest"
|
||||||
def test_func(_pytest):
|
def test_func(_pytest):
|
||||||
class ApiClass:
|
class ApiClass:
|
||||||
def xyz(self, arg): pass
|
def pytest_xyz(self, arg): "x"
|
||||||
hook = HookRelay([ApiClass], Registry())
|
hook = HookRelay([ApiClass], Registry())
|
||||||
rec = _pytest.gethookrecorder(hook)
|
rec = _pytest.gethookrecorder(hook)
|
||||||
class Plugin:
|
class Plugin:
|
||||||
def xyz(self, arg):
|
def pytest_xyz(self, arg):
|
||||||
return arg + 1
|
return arg + 1
|
||||||
rec._registry.register(Plugin())
|
rec._registry.register(Plugin())
|
||||||
res = rec.hook.xyz(arg=41)
|
res = rec.hook.pytest_xyz(arg=41)
|
||||||
assert res == [42]
|
assert res == [42]
|
||||||
""")
|
""")
|
||||||
reprec.assertoutcome(passed=1)
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
Loading…
Reference in New Issue