2009-07-09 01:18:26 +08:00
|
|
|
""" log invocations of extension hooks to a file. """
|
2009-05-21 05:12:37 +08:00
|
|
|
import py
|
|
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption("--hooklog", dest="hooklog", default=None,
|
|
|
|
help="write hook calls to the given file.")
|
|
|
|
|
|
|
|
def pytest_configure(config):
|
|
|
|
hooklog = config.getvalue("hooklog")
|
|
|
|
if hooklog:
|
|
|
|
assert not config.pluginmanager.comregistry.logfile
|
|
|
|
config.pluginmanager.comregistry.logfile = open(hooklog, 'w')
|
|
|
|
|
|
|
|
def pytest_unconfigure(config):
|
|
|
|
f = config.pluginmanager.comregistry.logfile
|
|
|
|
if f:
|
|
|
|
f.close()
|
|
|
|
config.pluginmanager.comregistry.logfile = None
|
|
|
|
|
|
|
|
# ===============================================================================
|
|
|
|
# plugin tests
|
|
|
|
# ===============================================================================
|
|
|
|
|
|
|
|
def test_functional(testdir):
|
|
|
|
testdir.makepyfile("""
|
|
|
|
def test_pass():
|
|
|
|
pass
|
|
|
|
""")
|
|
|
|
testdir.runpytest("--hooklog=hook.log")
|
|
|
|
s = testdir.tmpdir.join("hook.log").read()
|
2009-05-23 03:53:26 +08:00
|
|
|
assert s.find("pytest_sessionstart") != -1
|
2009-05-21 05:12:37 +08:00
|
|
|
assert s.find("ItemTestReport") != -1
|
2009-05-23 03:53:26 +08:00
|
|
|
assert s.find("sessionfinish") != -1
|