From 7b7737bf9694001a00b556ceacd0477b5dd5ae4a Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 6 Dec 2015 13:21:52 +0100 Subject: [PATCH] handle duplicate test ids via collection and xdist each reporting --- _pytest/junitxml.py | 20 +++++++++++++------- testing/test_junitxml.py | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index c4798b586..1c114ddcb 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -262,12 +262,18 @@ class LogXML(object): self.node_reporters = {} # nodeid -> _NodeReporter self.node_reporters_ordered = [] - def node_reporter(self, nodeid): - if nodeid in self.node_reporters: + def node_reporter(self, report): + nodeid = getattr(report, 'nodeid', report) + # local hack to handle xdist report order + slavenode = getattr(report, 'node', None) + + key = nodeid, slavenode + + if key in self.node_reporters: #TODO: breasks for --dist=each - return self.node_reporters[nodeid] + return self.node_reporters[key] reporter = _NodeReporter(nodeid, self) - self.node_reporters[nodeid] = reporter + self.node_reporters[key] = reporter self.node_reporters_ordered.append(reporter) return reporter @@ -276,7 +282,7 @@ class LogXML(object): self.stats[key] += 1 def _opentestcase(self, report): - reporter = self.node_reporter(report.nodeid) + reporter = self.node_reporter(report) reporter.record_testreport(report) return reporter @@ -318,13 +324,13 @@ class LogXML(object): reporter.append_skipped(report) self.update_testcase_duration(report) if report.when == "teardown": - self.node_reporter(report.nodeid).finalize() + self.node_reporter(report).finalize() def update_testcase_duration(self, report): """accumulates total duration for nodeid from given report and updates the Junit.testcase with the new total if already created. """ - reporter = self.node_reporter(report.nodeid) + reporter = self.node_reporter(report) reporter.duration += getattr(report, 'duration', 0.0) def pytest_collectreport(self, report): diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index 9ee6824c3..81a8f4e6a 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -661,7 +661,6 @@ def test_random_report_log_xdist(testdir): assert failed == ['test_x[22]'] -@pytest.mark.xfail(reason='duplicate test ids kill us') def test_runs_twice(testdir): f = testdir.makepyfile(''' def test_pass(): @@ -669,4 +668,17 @@ def test_runs_twice(testdir): ''') result = testdir.runpytest(f, f, '--junitxml', testdir.tmpdir.join("test.xml")) - assert 'INTERNALERROR' not in result.stdout \ No newline at end of file + assert 'INTERNALERROR' not in str(result.stdout) + + +def test_runs_twice_xdist(testdir): + pytest.importorskip('xdist') + f = testdir.makepyfile(''' + def test_pass(): + pass + ''') + + result = testdir.runpytest(f, + '--dist', 'each', '--tx', '2*popen', + '--junitxml', testdir.tmpdir.join("test.xml")) + assert 'INTERNALERROR' not in str(result.stdout) \ No newline at end of file