handle duplicate test ids via collection and xdist each reporting

This commit is contained in:
Ronny Pfannschmidt 2015-12-06 13:21:52 +01:00
parent 04e9ae75c8
commit 7b7737bf96
2 changed files with 27 additions and 9 deletions

View File

@ -262,12 +262,18 @@ class LogXML(object):
self.node_reporters = {} # nodeid -> _NodeReporter self.node_reporters = {} # nodeid -> _NodeReporter
self.node_reporters_ordered = [] self.node_reporters_ordered = []
def node_reporter(self, nodeid): def node_reporter(self, report):
if nodeid in self.node_reporters: 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 #TODO: breasks for --dist=each
return self.node_reporters[nodeid] return self.node_reporters[key]
reporter = _NodeReporter(nodeid, self) reporter = _NodeReporter(nodeid, self)
self.node_reporters[nodeid] = reporter self.node_reporters[key] = reporter
self.node_reporters_ordered.append(reporter) self.node_reporters_ordered.append(reporter)
return reporter return reporter
@ -276,7 +282,7 @@ class LogXML(object):
self.stats[key] += 1 self.stats[key] += 1
def _opentestcase(self, report): def _opentestcase(self, report):
reporter = self.node_reporter(report.nodeid) reporter = self.node_reporter(report)
reporter.record_testreport(report) reporter.record_testreport(report)
return reporter return reporter
@ -318,13 +324,13 @@ class LogXML(object):
reporter.append_skipped(report) reporter.append_skipped(report)
self.update_testcase_duration(report) self.update_testcase_duration(report)
if report.when == "teardown": if report.when == "teardown":
self.node_reporter(report.nodeid).finalize() self.node_reporter(report).finalize()
def update_testcase_duration(self, report): def update_testcase_duration(self, report):
"""accumulates total duration for nodeid from given report and updates """accumulates total duration for nodeid from given report and updates
the Junit.testcase with the new total if already created. 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) reporter.duration += getattr(report, 'duration', 0.0)
def pytest_collectreport(self, report): def pytest_collectreport(self, report):

View File

@ -661,7 +661,6 @@ def test_random_report_log_xdist(testdir):
assert failed == ['test_x[22]'] assert failed == ['test_x[22]']
@pytest.mark.xfail(reason='duplicate test ids kill us')
def test_runs_twice(testdir): def test_runs_twice(testdir):
f = testdir.makepyfile(''' f = testdir.makepyfile('''
def test_pass(): def test_pass():
@ -669,4 +668,17 @@ def test_runs_twice(testdir):
''') ''')
result = testdir.runpytest(f, f, '--junitxml', testdir.tmpdir.join("test.xml")) result = testdir.runpytest(f, f, '--junitxml', testdir.tmpdir.join("test.xml"))
assert 'INTERNALERROR' not in result.stdout 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)