[py-svn] r61303 - in py/branch/pytestplugin/py/test: . dsession dsession/testing looponfail/testing plugin plugin/testing testing
hpk at codespeak.net
hpk at codespeak.net
Sat Jan 24 14:44:32 CET 2009
Author: hpk
Date: Sat Jan 24 14:44:31 2009
New Revision: 61303
Modified:
py/branch/pytestplugin/py/test/dsession/dsession.py
py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py
py/branch/pytestplugin/py/test/event.py
py/branch/pytestplugin/py/test/looponfail/testing/test_util.py
py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
py/branch/pytestplugin/py/test/plugin/pytest_terminal.py
py/branch/pytestplugin/py/test/plugin/testing/test_terminal.py
py/branch/pytestplugin/py/test/runner.py
py/branch/pytestplugin/py/test/testing/test_event.py
py/branch/pytestplugin/py/test/testing/test_runner_functional.py
py/branch/pytestplugin/py/test/testing/test_session.py
Log:
* unify CollectionReport and ItemTestReport attributes some more
* move their construction into constructor of the respective classes
this simplifies the runner protocol (see runner.py)
Modified: py/branch/pytestplugin/py/test/dsession/dsession.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/dsession.py (original)
+++ py/branch/pytestplugin/py/test/dsession/dsession.py Sat Jan 24 14:44:31 2009
@@ -12,7 +12,6 @@
Collector = (py.test.collect.Collector, py.test.collect.Collector)
from py.__.test.runner import basic_run_report, basic_collect_report
from py.__.test.session import Session
-from py.__.test.runner import OutcomeRepr
from py.__.test import outcome
import Queue
@@ -221,9 +220,8 @@
self.trace("removed %r, host=%r" %(item,host.hostid))
def handle_crashitem(self, item, host):
- longrepr = "%r CRASHED THE HOST %r" %(item, host)
- outcome = OutcomeRepr(when="execute", shortrepr="c", longrepr=longrepr)
- rep = event.ItemTestReport(item, failed=outcome)
+ longrepr = "!!! Host %r crashed during running of test %r" %(host, item)
+ rep = event.ItemTestReport(item, when="???", excinfo=longrepr)
self.bus.notify(rep)
def setup_hosts(self):
Modified: py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py
==============================================================================
--- py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py (original)
+++ py/branch/pytestplugin/py/test/dsession/testing/test_dsession.py Sat Jan 24 14:44:31 2009
@@ -182,8 +182,8 @@
testrep = [x for x in events if isinstance(x, event.ItemTestReport)][0]
assert testrep.failed
assert testrep.colitem == item1
- assert str(testrep.outcome.longrepr).find("CRASHED") != -1
- assert str(testrep.outcome.longrepr).find(host.hostname) != -1
+ assert str(testrep.longrepr).find("crashed") != -1
+ assert str(testrep.longrepr).find(host.hostname) != -1
def test_hostup_adds_to_available(self):
item = self.getitem("def test_func(): pass")
Modified: py/branch/pytestplugin/py/test/event.py
==============================================================================
--- py/branch/pytestplugin/py/test/event.py (original)
+++ py/branch/pytestplugin/py/test/event.py Sat Jan 24 14:44:31 2009
@@ -75,16 +75,8 @@
class BaseReport(BaseEvent):
- failed = passed = skipped = None
- def __init__(self, colitem, **kwargs):
- self.colitem = colitem
- assert len(kwargs) == 1, kwargs
- name, value = kwargs.items()[0]
- setattr(self, name, True)
- self.outcome = value
-
def toterminal(self, out):
- longrepr = self.outcome.longrepr
+ longrepr = self.longrepr
if hasattr(longrepr, 'toterminal'):
longrepr.toterminal(out)
else:
@@ -92,7 +84,34 @@
class ItemTestReport(BaseReport):
""" Test Execution Report. """
+ failed = passed = skipped = False
+ def __init__(self, colitem, excinfo=None, when=None, outerr=None):
+ self.colitem = colitem
+ if not excinfo:
+ self.passed = True
+ self.shortrepr = "."
+ else:
+ self.when = when
+ if not isinstance(excinfo, py.code.ExceptionInfo):
+ self.failed = True
+ shortrepr = "?"
+ longrepr = excinfo
+ elif excinfo.errisinstance(Skipped):
+ self.skipped = True
+ shortrepr = "s"
+ longrepr = self.colitem._repr_failure_py(excinfo, outerr)
+ else:
+ self.failed = True
+ shortrepr = self.colitem.shortfailurerepr
+ if self.when == "execute":
+ longrepr = self.colitem.repr_failure(excinfo, outerr)
+ else: # exception in setup or teardown
+ longrepr = self.colitem._repr_failure_py(excinfo, outerr)
+ shortrepr = shortrepr.lower()
+ self.shortrepr = shortrepr
+ self.longrepr = longrepr
+
class CollectionStart(BaseEvent):
def __init__(self, collector):
self.collector = collector
Modified: py/branch/pytestplugin/py/test/looponfail/testing/test_util.py
==============================================================================
--- py/branch/pytestplugin/py/test/looponfail/testing/test_util.py (original)
+++ py/branch/pytestplugin/py/test/looponfail/testing/test_util.py Sat Jan 24 14:44:31 2009
@@ -69,7 +69,8 @@
bus.notify(event.NOP())
assert recorder.events
assert not recorder.getfailures()
- rep = event.ItemTestReport(None, failed=True)
+ rep = event.ItemTestReport(None, None)
+ rep.failed = True
bus.notify(rep)
failures = recorder.getfailures()
assert failures == [rep]
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 Sat Jan 24 14:44:31 2009
@@ -59,24 +59,28 @@
if isinstance(ev, ev.CollectionReport):
# encode pass/fail/skip indepedent of terminal reporting semantics
# XXX handle collection and item reports more uniformly
- if ev.passed:
- code = "."
- else:
- if ev.failed:
- code = "F"
- elif ev.skipped:
- code = "S"
+ assert not ev.passed
+ if ev.failed:
+ code = "F"
+ elif ev.skipped:
+ code = "S"
longrepr = str(ev.longrepr.reprcrash)
else:
assert isinstance(ev, ev.ItemTestReport)
- code = ev.outcome.shortrepr # XXX make independent from reporting
- longrepr = str(ev.outcome.longrepr)
+ code = ev.shortrepr
+ if ev.passed:
+ longrepr = ""
+ elif ev.failed:
+ longrepr = str(ev.longrepr)
+ elif ev.skipped:
+ longrepr = str(ev.longrepr.reprcrash.message)
return code, longrepr
def log_outcome(self, ev):
- gpath = generic_path(ev.colitem)
- shortrepr, longrepr = self.getoutcomecodes(ev)
- self.write_log_entry(shortrepr, gpath, longrepr)
+ if (not ev.passed or isinstance(ev, ev.ItemTestReport)):
+ gpath = generic_path(ev.colitem)
+ shortrepr, longrepr = self.getoutcomecodes(ev)
+ self.write_log_entry(shortrepr, gpath, longrepr)
def log_event_to_file(self, ev):
if isinstance(ev, ev.ItemTestReport):
Modified: py/branch/pytestplugin/py/test/plugin/pytest_terminal.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_terminal.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_terminal.py Sat Jan 24 14:44:31 2009
@@ -74,11 +74,7 @@
def _folded_skips(self):
d = {}
for event in self._skipped:
- if isinstance(event, event.CollectionReport):
- longrepr = event.longrepr
- entry = event.longrepr.reprcrash
- else:
- entry = event.outcome.longrepr
+ entry = event.longrepr.reprcrash
key = entry.path, entry.lineno, entry.message
d.setdefault(key, []).append(event)
l = []
@@ -131,14 +127,18 @@
self.ensure_newline()
self._tw.sep(sep, title, **markup)
- def getoutcomeletter(self, item):
- return item.outcome.shortrepr
+ def getoutcomeletter(self, event):
+ return event.shortrepr
- def getoutcomeword(self, item):
- if item.passed: return self._tw.markup("PASS", green=True)
- elif item.failed: return self._tw.markup("FAIL", red=True)
- elif item.skipped: return "SKIP"
- else: return self._tw.markup("???", red=True)
+ def getoutcomeword(self, event):
+ if event.passed:
+ return self._tw.markup("PASS", green=True)
+ elif event.failed:
+ return self._tw.markup("FAIL", red=True)
+ elif event.skipped:
+ return "SKIP"
+ else:
+ return self._tw.markup("???", red=True)
def rep_InternalException(self, ev):
for line in str(ev.repr).split("\n"):
@@ -226,9 +226,9 @@
self.write_sep("#", "LOOPONFAILING", red=True)
for report in ev.failreports:
try:
- loc = report.outcome.longrepr.reprcrash
+ loc = report.longrepr.reprcrash
except AttributeError:
- loc = str(report.outcome.longrepr)[:50]
+ loc = str(report.longrepr)[:50]
self.write_line(loc, red=True)
self.write_sep("#", "waiting for changes")
for rootdir in ev.rootdirs:
Modified: py/branch/pytestplugin/py/test/plugin/testing/test_terminal.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/testing/test_terminal.py (original)
+++ py/branch/pytestplugin/py/test/plugin/testing/test_terminal.py Sat Jan 24 14:44:31 2009
@@ -318,7 +318,8 @@
def test_TestItemReport_one(self):
for outcome in 'passed skipped failed'.split():
rep = BaseReporter()
- ev = event.ItemTestReport(None, **{outcome:True})
+ ev = event.ItemTestReport(None)
+ setattr(ev, outcome, True)
rep.processevent(ev)
assert getattr(rep, '_' + outcome) == [ev]
@@ -343,9 +344,8 @@
ev1.skipped = True
ev1.longrepr = longrepr
- from py.__.test.runner import OutcomeRepr
- out2 = OutcomeRepr(None, None, longrepr.reprcrash)
- ev2 = event.ItemTestReport(None, skipped=out2)
+ ev2 = event.ItemTestReport(None, excinfo=longrepr)
+ ev2.skipped = True
rep.processevent(ev1)
rep.processevent(ev2)
assert len(rep._skipped) == 2
Modified: py/branch/pytestplugin/py/test/runner.py
==============================================================================
--- py/branch/pytestplugin/py/test/runner.py (original)
+++ py/branch/pytestplugin/py/test/runner.py Sat Jan 24 14:44:31 2009
@@ -48,23 +48,6 @@
excinfo = py.code.ExceptionInfo()
return self.makereport(res, when, excinfo, outerr)
- def getkw(self, when, excinfo, outerr):
- """construct keyword arguments for a non-passing run of a collector"""
- if excinfo.errisinstance(Skipped):
- outcome = "skipped"
- shortrepr = "s"
- longrepr = excinfo._getreprcrash()
- else:
- outcome = "failed"
- if when == "execute":
- longrepr = self.colitem.repr_failure(excinfo, outerr)
- shortrepr = self.colitem.shortfailurerepr
- else:
- longrepr = self.colitem._repr_failure_py(excinfo, outerr)
- shortrepr = self.colitem.shortfailurerepr.lower()
- kw = { outcome: OutcomeRepr(when, shortrepr, longrepr)}
- return kw
-
class ItemRunner(RobustRun):
def setup(self):
self.colitem._setupstate.prepare(self.colitem)
@@ -76,11 +59,7 @@
#self.colitem.config.pluginmanager.post_execute(self.colitem)
def makereport(self, res, when, excinfo, outerr):
- if excinfo:
- kw = self.getkw(when, excinfo, outerr)
- else:
- kw = {'passed': OutcomeRepr(when, '.', "")}
- testrep = event.ItemTestReport(self.colitem, **kw)
+ testrep = event.ItemTestReport(self.colitem, excinfo, when, outerr)
if self.pdb and testrep.failed:
tw = py.io.TerminalWriter()
testrep.toterminal(tw)
@@ -97,26 +76,11 @@
def makereport(self, res, when, excinfo, outerr):
return event.CollectionReport(self.colitem, res, excinfo, when, outerr)
-# if excinfo:
-# kw = self.getkw(when, excinfo, outerr)
-# else:
-# kw = {'passed': OutcomeRepr(when, '', "")}
-# return event.CollectionReport(self.colitem, res, **kw)
-
NORESULT = object()
#
# public entrypoints / objects
#
-class OutcomeRepr(object):
- def __init__(self, when, shortrepr, longrepr):
- self.when = when
- self.shortrepr = shortrepr
- self.longrepr = longrepr
- def __str__(self):
- return "<OutcomeRepr when=%r, shortrepr=%r, len-longrepr=%s" %(
- self.when, self.shortrepr, len(str(self.longrepr)))
-
def basic_collect_report(item):
return CollectorRunner(item).run()
@@ -145,13 +109,17 @@
else:
if result.exitstatus == EXITSTATUS_TESTEXIT:
raise Exit("forked test item %s raised Exit" %(item,))
- return report_crash(item, result)
+ return report_process_crash(item, result)
-def report_crash(item, result):
+def report_process_crash(item, result):
path, lineno = item.getfslineno()
longrepr = [
("X", "CRASHED"),
("%s:%s: CRASHED with signal %d" %(path, lineno, result.signal)),
]
- outcomerepr = OutcomeRepr(when="???", shortrepr="C", longrepr=longrepr)
- return event.ItemTestReport(item, failed=outcomerepr)
+ # XXX hackish to modify "pass" event
+ ev = event.ItemTestReport(item)
+ ev.failed = True
+ ev.when = "???"
+ ev.longrepr = longrepr
+ return ev
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 Sat Jan 24 14:44:31 2009
@@ -41,6 +41,14 @@
assert hasattr(event.BaseEvent, value.__name__)
class TestItemTestReport(suptest.InlineCollection):
+ def test_excinfo_is_longrepr(self):
+ modcol = self.getmodulecol("def test_ok(): pass")
+ ev = event.ItemTestReport(modcol, excinfo="hello")
+ twmock = TWMock()
+ ev.toterminal(twmock)
+ assert twmock.lines
+ assert twmock.lines[0] == "hello"
+
def test_toterminal(self):
sorter = suptest.events_from_runsource("""
def test_one():
@@ -53,7 +61,7 @@
ev.toterminal(twmock)
assert twmock.lines
twmock = TWMock()
- ev.outcome.longrepr = "hello"
+ ev.longrepr = "hello"
ev.toterminal(twmock)
assert twmock.lines[0] == "hello"
assert not twmock.lines[1:]
Modified: py/branch/pytestplugin/py/test/testing/test_runner_functional.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_runner_functional.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_runner_functional.py Sat Jan 24 14:44:31 2009
@@ -12,8 +12,8 @@
""")
assert ev.passed
assert not ev.failed
- assert ev.outcome.shortrepr == "."
- assert not ev.outcome.longrepr
+ assert ev.shortrepr == "."
+ assert not hasattr(ev, 'longrepr')
def test_failfunction(self):
ev = self.runitem("""
@@ -23,9 +23,9 @@
assert not ev.passed
assert not ev.skipped
assert ev.failed
- assert ev.outcome.when == "execute"
- assert isinstance(ev.outcome.longrepr, ReprExceptionInfo)
- assert str(ev.outcome.shortrepr) == "F"
+ assert ev.when == "execute"
+ assert isinstance(ev.longrepr, ReprExceptionInfo)
+ assert str(ev.shortrepr) == "F"
def test_skipfunction(self):
ev = self.runitem("""
@@ -71,7 +71,7 @@
assert not ev.skipped
assert not ev.passed
assert ev.failed
- assert ev.outcome.when == "setup"
+ assert ev.when == "setup"
def test_failure_in_teardown_function(self):
ev = self.runitem("""
@@ -85,9 +85,9 @@
assert not ev.skipped
assert not ev.passed
assert ev.failed
- #assert ev.outcome.when == "teardown"
- #assert ev.outcome.where.lineno == 3
- #assert ev.outcome.entries
+ assert ev.when == "teardown"
+ assert ev.longrepr.reprcrash.lineno == 3
+ assert ev.longrepr.reprtraceback.reprentries
def test_custom_failure_repr(self):
self.makepyfile(conftest="""
@@ -157,7 +157,7 @@
except SystemExit:
py.test.fail("runner did not catch SystemExit")
assert ev.failed
- assert ev.outcome.when == "execute"
+ assert ev.when == "execute"
def test_exit_propagates(self):
from py.__.test.outcome import Exit
@@ -195,7 +195,7 @@
assert 0
""", pdb=l.append)
assert ev.failed
- assert ev.outcome.when == "execute"
+ assert ev.when == "execute"
assert len(l) == 1
def test_pdb_on_skip(self):
@@ -221,7 +221,7 @@
os.kill(os.getpid(), 15)
""")
assert ev.failed
- assert ev.outcome.when == "???"
+ assert ev.when == "???"
class TestCollectionEvent(InlineCollection):
def test_collect_result(self):
Modified: py/branch/pytestplugin/py/test/testing/test_session.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_session.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_session.py Sat Jan 24 14:44:31 2009
@@ -134,7 +134,7 @@
sorter = self.events_from_cmdline()
passed, skipped, failed = sorter.listoutcomes()
assert len(failed) == 1
- out = failed[0].outcome.longrepr.reprcrash.message
+ out = failed[0].longrepr.reprcrash.message
if not out.find("DID NOT RAISE") != -1:
print out
py.test.fail("incorrect raises() output")
@@ -193,9 +193,9 @@
sorter = self.events_from_cmdline()
passed, skipped, failed = sorter.listoutcomes()
assert len(failed) == 2
- out = failed[0].outcome.longrepr.reprcrash.message
+ out = failed[0].longrepr.reprcrash.message
assert out.find("""[Exception("Ha Ha fooled you, I'm a broken repr().") raised in repr()]""") != -1 #'
- out = failed[1].outcome.longrepr.reprcrash.message
+ out = failed[1].longrepr.reprcrash.message
assert (out.find("[unknown exception raised in repr()]") != -1 or
out.find("TypeError") != -1)
More information about the pytest-commit
mailing list