Fix user_properties not saved to XML if fixture errors during teardown (#11382)

Move handling of user_properties to `finalize()`.

Previously if a fixture failed during teardown, `pytest_runtest_logreport` would not be called with "teardown", resulting in the user properties not being saved on the JUnit XML file.

Fixes: #11367
(cherry picked from commit 917ce9aa01)

Co-authored-by: Israel Fruchter <israel.fruchter@gmail.com>
This commit is contained in:
Bruno Oliveira
2023-09-03 15:01:56 -03:00
committed by GitHub
parent 82eb86f707
commit 7f5d9b9df4
4 changed files with 37 additions and 3 deletions

View File

@@ -502,6 +502,10 @@ class LogXML:
# Local hack to handle xdist report order.
workernode = getattr(report, "node", None)
reporter = self.node_reporters.pop((nodeid, workernode))
for propname, propvalue in report.user_properties:
reporter.add_property(propname, str(propvalue))
if reporter is not None:
reporter.finalize()
@@ -599,9 +603,6 @@ class LogXML:
reporter = self._opentestcase(report)
reporter.write_captured_output(report)
for propname, propvalue in report.user_properties:
reporter.add_property(propname, str(propvalue))
self.finalize(report)
report_wid = getattr(report, "worker_id", None)
report_ii = getattr(report, "item_index", None)