merge _pytest into pytester self-testing plugin

--HG--
branch : trunk
This commit is contained in:
holger krekel
2010-10-12 13:10:39 +02:00
parent 07c835fdf3
commit 7453fc107c
4 changed files with 164 additions and 171 deletions

View File

@@ -1,5 +1,7 @@
import py
from pytest.plugin.pytester import LineMatcher, LineComp
import os, sys
from pytest.plugin.pytester import LineMatcher, LineComp, HookRecorder
from pytest._core import Registry
def test_reportrecorder(testdir):
item = testdir.getitem("def test_func(): pass")
@@ -69,3 +71,44 @@ def test_testdir_runs_with_plugin(testdir):
"*1 passed*"
])
def test_hookrecorder_basic():
rec = HookRecorder(Registry())
class ApiClass:
def pytest_xyz(self, arg):
"x"
rec.start_recording(ApiClass)
rec.hook.pytest_xyz(arg=123)
call = rec.popcall("pytest_xyz")
assert call.arg == 123
assert call._name == "pytest_xyz"
py.test.raises(ValueError, "rec.popcall('abc')")
def test_hookrecorder_basic_no_args_hook():
rec = HookRecorder(Registry())
apimod = type(os)('api')
def pytest_xyz():
"x"
apimod.pytest_xyz = pytest_xyz
rec.start_recording(apimod)
rec.hook.pytest_xyz()
call = rec.popcall("pytest_xyz")
assert call._name == "pytest_xyz"
def test_functional(testdir, linecomp):
reprec = testdir.inline_runsource("""
import py
from pytest._core import HookRelay, Registry
pytest_plugins="pytester"
def test_func(_pytest):
class ApiClass:
def pytest_xyz(self, arg): "x"
hook = HookRelay([ApiClass], Registry())
rec = _pytest.gethookrecorder(hook)
class Plugin:
def pytest_xyz(self, arg):
return arg + 1
rec._registry.register(Plugin())
res = rec.hook.pytest_xyz(arg=41)
assert res == [42]
""")
reprec.assertoutcome(passed=1)