[py-svn] r60993 - in py/branch/pytestplugin/py/test: . dsession/testing plugin plugin/testing testing
hpk at codespeak.net
hpk at codespeak.net
Thu Jan 15 14:28:24 CET 2009
Author: hpk
Date: Thu Jan 15 14:28:23 2009
New Revision: 60993
Modified:
py/branch/pytestplugin/py/test/defaultconftest.py
py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py
py/branch/pytestplugin/py/test/event.py
py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
py/branch/pytestplugin/py/test/plugin/testing/test_resultlog.py
py/branch/pytestplugin/py/test/session.py
py/branch/pytestplugin/py/test/testing/test_config.py
py/branch/pytestplugin/py/test/testing/test_event.py
Log:
* factoring eventlogging into another plugin
* making eventclasses available on events for easier isinstance-checking
* normalizing/refining planned plugin-API a bit more
Modified: py/branch/pytestplugin/py/test/defaultconftest.py
==============================================================================
--- py/branch/pytestplugin/py/test/defaultconftest.py (original)
+++ py/branch/pytestplugin/py/test/defaultconftest.py Thu Jan 15 14:28:23 2009
@@ -52,9 +52,6 @@
Option('', '--pdb',
action="store_true", dest="usepdb", default=False,
help="start pdb (the Python debugger) on errors."),
- Option('', '--eventlog',
- action="store", dest="eventlog", default=None,
- help="write reporting events to given file."),
Option('', '--tracedir',
action="store", dest="tracedir", default=None,
help="write tracing information to the given directory."),
Modified: py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py (original)
+++ py/branch/pytestplugin/py/test/dsession/testing/test_functional_dsession.py Thu Jan 15 14:28:23 2009
@@ -32,15 +32,6 @@
config = self.parseconfig(self.tmpdir, '-d')
py.test.raises(SystemExit, "config.initsession()")
- def test_session_eventlog_dist(self):
- self.makepyfile(conftest="dist_hosts=['localhost']\n")
- eventlog = self.tmpdir.join("mylog")
- config = self.parseconfig(self.tmpdir, '-d', '--eventlog=%s' % eventlog)
- session = config.initsession()
- session.bus.notify(event.TestrunStart())
- s = eventlog.read()
- assert s.find("TestrunStart") != -1
-
def test_conftest_options(self):
self.makepyfile(conftest="""
print "importing conftest"
Modified: py/branch/pytestplugin/py/test/event.py
==============================================================================
--- py/branch/pytestplugin/py/test/event.py (original)
+++ py/branch/pytestplugin/py/test/event.py Thu Jan 15 14:28:23 2009
@@ -151,3 +151,12 @@
self.host = host
self.root = root
+
+# make all eventclasses available on BaseEvent so that
+# consumers of events can easily filter by
+# 'isinstance(event, event.Name)' checks
+
+for name, cls in vars().items():
+ if hasattr(cls, '__bases__') and issubclass(cls, BaseEvent):
+ setattr(BaseEvent, name, cls)
+#
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 14:28:23 2009
@@ -1,14 +1,19 @@
"""
pytest "resultlog" plugin for machine-readable logging of test results.
-
"""
+plugin_name = "pytest_resultlog"
+plugin_version = "0.1"
+plugin_author = "Samuele Pedroni, Anders Hammarquist"
+
import py
-from py.__.test import event
-def register_plugin(config):
+def pytest_initplugin(config):
config.register_plugin(ResultLogPlugin())
class ResultLogPlugin:
+ __doc__ = __doc__
+ resultlog = None
+
def pytest_addoptions(self, config):
config.addoptions("resultlog options",
config.Option('--resultlog', action="store",
@@ -23,7 +28,7 @@
self.resultlog = ResultLog(logfile)
def pytest_unconfigure(self, config):
- if hasattr(self, 'resultlog'):
+ if self.resultlog:
self.resultlog.logfile.close()
del self.resultlog
@@ -70,11 +75,11 @@
self.write_log_entry(outcome.shortrepr, gpath, str(outcome.longrepr))
def log_event_to_file(self, ev):
- if isinstance(ev, event.ItemTestReport):
+ if isinstance(ev, ev.ItemTestReport):
self.log_outcome(ev)
- elif isinstance(ev, event.CollectionReport):
+ elif isinstance(ev, ev.CollectionReport):
if not ev.passed:
self.log_outcome(ev)
- elif isinstance(ev, event.InternalException):
+ elif isinstance(ev, ev.InternalException):
path = ev.repr.reprcrash.path # fishing :(
self.write_log_entry('!', path, str(ev.repr))
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 14:28:23 2009
@@ -62,7 +62,7 @@
myplugin.pytest_configure(config)
assert myplugin.resultlog
myplugin.pytest_unconfigure(config)
- assert not hasattr(myplugin, 'resultlog')
+ assert not myplugin.resultlog
class TestResultLog(object):
def test_write_log_entry(self):
Modified: py/branch/pytestplugin/py/test/session.py
==============================================================================
--- py/branch/pytestplugin/py/test/session.py (original)
+++ py/branch/pytestplugin/py/test/session.py Thu Jan 15 14:28:23 2009
@@ -26,14 +26,6 @@
self.config = config
self.bus = EventBus()
self._nomatch = False
- eventlog = self.config.option.eventlog
- if eventlog:
- self.eventlog = py.path.local(eventlog)
- f = self.eventlog.open("w")
- def eventwrite(ev):
- print >>f, ev
- f.flush()
- self.bus.subscribe(eventwrite)
def fixoptions(self):
""" check, fix and determine conflicting options. """
Modified: py/branch/pytestplugin/py/test/testing/test_config.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_config.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_config.py Thu Jan 15 14:28:23 2009
@@ -172,15 +172,6 @@
assert 42 == 43
""")
- def test_session_eventlog(self):
- eventlog = self.tmpdir.join("test_session_eventlog")
- config = py.test.config._reparse([self.tmpdir,
- '--eventlog=%s' % eventlog])
- session = config.initsession()
- session.bus.notify(event.TestrunStart())
- s = eventlog.read()
- assert s.find("TestrunStart") != -1
-
def test_tracedir_tracer(self):
tracedir = self.tmpdir.join("tracedir")
config = py.test.config._reparse([self.tmpdir,
Modified: py/branch/pytestplugin/py/test/testing/test_event.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_event.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_event.py Thu Jan 15 14:28:23 2009
@@ -35,6 +35,10 @@
bus.notify(2)
assert l == [1]
+def test_event_attributes():
+ for name, value in vars(event).items():
+ if py.std.inspect.isclass(value) and issubclass(value, event.BaseEvent):
+ assert hasattr(event.BaseEvent, value.__name__)
class TestItemTestReport(suptest.InlineCollection):
def test_toterminal(self):
More information about the pytest-commit
mailing list