[py-svn] r60991 - in py/branch/pytestplugin/py/test/plugin: . testing
hpk at codespeak.net
hpk at codespeak.net
Thu Jan 15 13:20:56 CET 2009
Author: hpk
Date: Thu Jan 15 13:20:54 2009
New Revision: 60991
Modified:
py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
py/branch/pytestplugin/py/test/plugin/testing/test_resultlog.py
Log:
* introduce configure/unconfigure hooks for plugins,
* some import cleanup
Modified: py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py Thu Jan 15 13:20:54 2009
@@ -1,3 +1,7 @@
+"""
+pytest "resultlog" plugin for machine-readable logging of test results.
+
+"""
import py
from py.__.test import event
@@ -12,16 +16,20 @@
help="path for machine-readable result log")
)
- def pytest_session_init(self, session):
- resultlog = session.config.option.resultlog
+ def pytest_configure(self, config):
+ resultlog = config.option.resultlog
if resultlog:
logfile = open(resultlog, 'w', 1) # line buffered
self.resultlog = ResultLog(logfile)
- session.bus.subscribe(self.resultlog.log_event_to_file)
- def pytest_session_finish(self, session):
+ def pytest_unconfigure(self, config):
if hasattr(self, 'resultlog'):
- session.bus.unsubscribe(self.resultlog.log_event_to_file)
+ self.resultlog.logfile.close()
+ del self.resultlog
+
+ def pytest_event(self, event):
+ if self.resultlog:
+ self.resultlog.log_event_to_file(event)
def generic_path(item):
chain = item.listchain()
Modified: py/branch/pytestplugin/py/test/plugin/testing/test_resultlog.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/testing/test_resultlog.py (original)
+++ py/branch/pytestplugin/py/test/plugin/testing/test_resultlog.py Thu Jan 15 13:20:54 2009
@@ -9,9 +9,6 @@
from py.__.test.testing import suptest
from py.__.test.config import Config
from py.__.test.collect import Node, Item, FSCollector
-from py.__.test.event import EventBus
-from py.__.test.event import ItemTestReport, CollectionReport
-from py.__.test.event import InternalException
from py.__.test.runner import OutcomeRepr
class Fake(object):
@@ -60,12 +57,12 @@
myplugin = resultlog.ResultLogPlugin()
config = Config()
myplugin.pytest_addoptions(config)
+ assert not config.option.resultlog
config.parse(['--resultlog=%s' % p])
- session = Session(config)
- myplugin.pytest_session_init(session)
- assert myplugin.resultlog.log_event_to_file in session.bus._subscribers
- myplugin.pytest_session_finish(session)
- assert myplugin.resultlog.log_event_to_file not in session.bus._subscribers
+ myplugin.pytest_configure(config)
+ assert myplugin.resultlog
+ myplugin.pytest_unconfigure(config)
+ assert not hasattr(myplugin, 'resultlog')
class TestResultLog(object):
def test_write_log_entry(self):
@@ -129,14 +126,14 @@
assert 'ValueError' in entry
def test_item_test_passed(self):
- bus = EventBus()
+ bus = event.EventBus()
reslog = resultlog.ResultLog(StringIO.StringIO())
bus.subscribe(reslog.log_event_to_file)
colitem = make_item('proj/test', 'proj/test/mod', 'a', 'b')
outcome=OutcomeRepr('execute', '.', '')
- rep_ev = ItemTestReport(colitem, passed=outcome)
+ rep_ev = event.ItemTestReport(colitem, passed=outcome)
bus.notify(rep_ev)
@@ -147,14 +144,14 @@
assert line[2:] == 'test/mod:a.b'
def test_collection_report(self):
- bus = EventBus()
+ bus = event.EventBus()
reslog = resultlog.ResultLog(None)
bus.subscribe(reslog.log_event_to_file)
reslog.logfile = StringIO.StringIO()
colitem = make_item('proj/test', 'proj/test/mod', 'A', None)
outcome=OutcomeRepr('execute', '', '')
- rep_ev = CollectionReport(colitem, object(), passed=outcome)
+ rep_ev = event.CollectionReport(colitem, object(), passed=outcome)
bus.notify(rep_ev)
@@ -163,7 +160,7 @@
reslog.logfile = StringIO.StringIO()
outcome=OutcomeRepr('execute', 'F', 'Some Error')
- rep_ev = CollectionReport(colitem, object(), failed=outcome)
+ rep_ev = event.CollectionReport(colitem, object(), failed=outcome)
bus.notify(rep_ev)
@@ -174,7 +171,7 @@
def test_internal_exception(self):
# they are produced for example by a teardown failing
# at the end of the run
- bus = EventBus()
+ bus = event.EventBus()
reslog = resultlog.ResultLog(StringIO.StringIO())
bus.subscribe(reslog.log_event_to_file)
@@ -183,7 +180,7 @@
except ValueError:
excinfo = py.code.ExceptionInfo()
- internal = InternalException(excinfo)
+ internal = event.InternalException(excinfo)
bus.notify(internal)
More information about the pytest-commit
mailing list