Skip to content

Commit

Permalink
Log failing reason exception in pytest report xml (#1036)
Browse files Browse the repository at this point in the history
Log exception details when failing reason doesn't match actual
exception.
  • Loading branch information
vbrkicTT authored Jan 23, 2025
1 parent 4d94bf2 commit fbec928
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions forge/test/operators/pytorch/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def pytest_runtest_makereport(item: _pytest.python.Function, call: _pytest.runne
if xfail_reason is not None: # an xfail reason is defined for the test
valid_reason = FailingReasonsValidation.validate_exception(exception_value, xfail_reason)

# if reason is not valid, mark the test as failed
# if reason is not valid, mark the test as failed and keep the original exception
if valid_reason == False:
report.outcome = "failed"
# Replace test report with a new one with outcome set to 'failed' and exception details
new_report = _pytest.reports.TestReport(
item=item,
when=call.when,
outcome="failed",
longrepr=call.excinfo.getrepr(style="long"),
sections=report.sections,
nodeid=report.nodeid,
location=report.location,
keywords=report.keywords,
)
outcome.force_result(new_report)
else:
logger.debug(f"Test '{item.name}' failed with exception: {type(exception_value)} '{exception_value}'")

0 comments on commit fbec928

Please sign in to comment.