Files
pytest2/py/test/plugin/pytest_eventlog.py
hpk c17a09adaf [svn r62211] merge 60797:HEAD of pytestplugin branch:
this merge contains:

* a new plugin architecture
* a pluginized pytest core
* many pytest related refactorings
* refactorings/streamlining of pytest's own tests

--HG--
branch : trunk
2009-02-27 11:18:27 +01:00

42 lines
1.3 KiB
Python

import py
class EventlogPlugin:
""" log pytest events to a file. """
def pytest_addoption(self, parser):
parser.addoption("--eventlog", dest="eventlog",
help="write all pytest events to the given file.")
def pytest_configure(self, config):
eventlog = config.getvalue("eventlog")
if eventlog:
self.eventlogfile = open(eventlog, 'w')
def pytest_unconfigure(self, config):
if hasattr(self, 'eventlogfile'):
self.eventlogfile.close()
del self.eventlogfile
def pyevent(self, eventname, *args, **kwargs):
if hasattr(self, 'eventlogfile'):
f = self.eventlogfile
print >>f, eventname, args, kwargs
f.flush()
# ===============================================================================
# plugin tests
# ===============================================================================
def test_generic(plugintester):
plugintester.apicheck(EventlogPlugin)
testdir = plugintester.testdir()
testdir.makepyfile("""
def test_pass():
pass
""")
testdir.runpytest("--eventlog=event.log")
s = testdir.tmpdir.join("event.log").read()
assert s.find("TestrunStart") != -1
assert s.find("ItemTestReport") != -1
assert s.find("TestrunFinish") != -1