kwarg support for reports, so xdist can deserialized extended reports

This commit is contained in:
Ronny Pfannschmidt 2012-01-20 19:50:45 +01:00
parent d88fe07377
commit 5263656df6
3 changed files with 28 additions and 3 deletions

View File

@ -11,6 +11,8 @@ Changes between 2.2.1 and 2.2.2.dev
e.g. from module, class and at function level. e.g. from module, class and at function level.
- add chdir method to monkeypatch funcarg - add chdir method to monkeypatch funcarg
- fix crash resulting from calling monkeypatch undo a second time - fix crash resulting from calling monkeypatch undo a second time
- extend reports accepting kwargs to set arbitrary additional attributes
this helps xdist serialization/deserialization of extended/customized reports
Changes between 2.2.0 and 2.2.1 Changes between 2.2.0 and 2.2.1
---------------------------------------- ----------------------------------------

View File

@ -141,6 +141,10 @@ def getslaveinfoline(node):
return s return s
class BaseReport(object): class BaseReport(object):
def __init__(self, **kw):
self.__dict__.update(kw)
def toterminal(self, out): def toterminal(self, out):
longrepr = self.longrepr longrepr = self.longrepr
if hasattr(self, 'node'): if hasattr(self, 'node'):
@ -190,7 +194,7 @@ class TestReport(BaseReport):
they fail). they fail).
""" """
def __init__(self, nodeid, location, def __init__(self, nodeid, location,
keywords, outcome, longrepr, when, sections=(), duration=0): keywords, outcome, longrepr, when, sections=(), duration=0, **extra):
#: normalized collection node id #: normalized collection node id
self.nodeid = nodeid self.nodeid = nodeid
@ -219,6 +223,8 @@ class TestReport(BaseReport):
#: time it took to run just the test #: time it took to run just the test
self.duration = duration self.duration = duration
self.__dict__.update(extra)
def __repr__(self): def __repr__(self):
return "<TestReport %r when=%r outcome=%r>" % ( return "<TestReport %r when=%r outcome=%r>" % (
self.nodeid, self.when, self.outcome) self.nodeid, self.when, self.outcome)
@ -226,9 +232,10 @@ class TestReport(BaseReport):
class TeardownErrorReport(BaseReport): class TeardownErrorReport(BaseReport):
outcome = "failed" outcome = "failed"
when = "teardown" when = "teardown"
def __init__(self, longrepr): def __init__(self, longrepr, **extra):
self.longrepr = longrepr self.longrepr = longrepr
self.sections = [] self.sections = []
self.__dict__.update(extra)
def pytest_make_collect_report(collector): def pytest_make_collect_report(collector):
call = CallInfo(collector._memocollect, "memocollect") call = CallInfo(collector._memocollect, "memocollect")
@ -250,12 +257,13 @@ def pytest_make_collect_report(collector):
getattr(call, 'result', None)) getattr(call, 'result', None))
class CollectReport(BaseReport): class CollectReport(BaseReport):
def __init__(self, nodeid, outcome, longrepr, result, sections=()): def __init__(self, nodeid, outcome, longrepr, result, sections=(), **extra):
self.nodeid = nodeid self.nodeid = nodeid
self.outcome = outcome self.outcome = outcome
self.longrepr = longrepr self.longrepr = longrepr
self.result = result or [] self.result = result or []
self.sections = list(sections) self.sections = list(sections)
self.__dict__.update(extra)
@property @property
def location(self): def location(self):

View File

@ -315,6 +315,21 @@ class TestSessionReports:
assert not rep.passed assert not rep.passed
assert rep.skipped assert rep.skipped
reporttypes = [
runner.BaseReport,
runner.TestReport,
runner.TeardownErrorReport,
runner.CollectReport,
]
@pytest.mark.parametrize('reporttype', reporttypes, ids=[x.__name__ for x in reporttypes])
def test_report_extra_parameters(reporttype):
args = py.std.inspect.getargspec(reporttype.__init__)[0][1:]
basekw = dict.fromkeys(args, [])
report = reporttype(newthing=1, **basekw)
assert report.newthing == 1
def test_callinfo(): def test_callinfo():
ci = runner.CallInfo(lambda: 0, '123') ci = runner.CallInfo(lambda: 0, '123')
assert ci.when == "123" assert ci.when == "123"