Skip to content

Commit c52480f

Browse files
committed
Added ouput capture for failing tests (issue 66) and fixed Lasagna subtest trunkation (issue 85).
1 parent f0e323f commit c52480f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

runner/__init__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,17 @@ def pytest_runtest_logreport(self, report):
6363
if report.passed and report.when != "call":
6464
return
6565

66-
# do not update tests that have already failed
66+
# Update tests that have already failed with capstdout and return.
6767
if not state.is_passing():
68+
if report.capstdout.rstrip('FFFFFFFF '):
69+
state.output = report.capstdout.rstrip('FFFFFFFF ')
6870
return
6971

70-
# captured relevant stdout content, if any
72+
# Record captured relevant stdout content for passed tests.
7173
if report.capstdout:
7274
state.output = report.capstdout
7375

74-
# handle test failure
76+
# Handle details of test failure
7577
if report.failed:
7678

7779
# traceback that caused the issued, if any
@@ -91,19 +93,22 @@ def pytest_runtest_logreport(self, report):
9193
source = Path(self.config.rootdir) / report.fspath
9294
state.test_code = TestOrder.function_source(test_id, source)
9395

96+
9497
# Looks up test_ids from parent when the test is a subtest.
9598
if state.task_id == 0 and 'variation' in state.name:
9699
parent_test_name = state.name.split(' ')[0]
97100
parent_task_id = self.tests[parent_test_name].task_id
98101
state.task_id = parent_task_id
99102

103+
100104
# Changes status of parent to fail if any of the subtests fail.
101105
if state.fail:
102106
self.tests[parent_test_name].fail(
103107
message="One or more variations of this test failed. Details can be found under each [variant#]."
104108
)
105109
self.tests[parent_test_name].test_code = state.test_code
106110

111+
107112
def pytest_sessionfinish(self, session, exitstatus):
108113
"""
109114
Processes the results into a report.
@@ -141,7 +146,7 @@ def pytest_exception_interact(self, node, call, report):
141146
err = excinfo.getrepr(style="no", abspath=False)
142147

143148
# trim off full traceback for first exercise to be friendlier and clearer
144-
if 'lasagna_test.py' in str(err.chain[0]):
149+
if 'Lasagna' in node.name and 'ImportError' in str(err.chain[0]):
145150
trace = err.chain[-2][0]
146151
else:
147152
trace = err.chain[-1][0]

0 commit comments

Comments
 (0)