Add longreprtext property to TestReport objects

Related to #1790
This commit is contained in:
Bruno Oliveira 2016-08-03 21:11:19 -03:00
parent 6759b042b5
commit 08002ab75a
3 changed files with 41 additions and 0 deletions

View File

@ -211,6 +211,20 @@ class BaseReport(object):
if name.startswith(prefix): if name.startswith(prefix):
yield prefix, content yield prefix, content
@property
def longreprtext(self):
"""
Read-only property that returns the full string representation
of ``longrepr``.
.. versionadded:: 3.0
"""
tw = py.io.TerminalWriter(stringio=True)
tw.hasmarkup = False
self.toterminal(tw)
exc = tw.stringio.getvalue()
return exc.strip()
passed = property(lambda x: x.outcome == "passed") passed = property(lambda x: x.outcome == "passed")
failed = property(lambda x: x.outcome == "failed") failed = property(lambda x: x.outcome == "failed")
skipped = property(lambda x: x.outcome == "skipped") skipped = property(lambda x: x.outcome == "skipped")

View File

@ -632,6 +632,7 @@ Reference of objects involved in hooks
.. autoclass:: _pytest.runner.TestReport() .. autoclass:: _pytest.runner.TestReport()
:members: :members:
:inherited-members:
.. autoclass:: _pytest.vendored_packages.pluggy._CallOutcome() .. autoclass:: _pytest.vendored_packages.pluggy._CallOutcome()
:members: :members:

View File

@ -668,3 +668,29 @@ def test_store_except_info_on_eror():
assert sys.last_type is IndexError assert sys.last_type is IndexError
assert sys.last_value.args[0] == 'TEST' assert sys.last_value.args[0] == 'TEST'
assert sys.last_traceback assert sys.last_traceback
class TestReportContents:
"""
Test ``longreprtext`` property of TestReport objects.
"""
def test_pass(self, testdir):
reports = testdir.runitem("""
def test_func():
pass
""")
rep = reports[1]
assert rep.longreprtext == ''
def test_failure(self, testdir):
reports = testdir.runitem("""
def test_func():
x = 1
assert x == 4
""")
rep = reports[1]
assert 'assert 1 == 4' in rep.longreprtext
def getrunner(self):
return lambda item: runner.runtestprotocol(item, log=False)