Skip to content

Commit e83aae6

Browse files
Merge pull request #125 from reginaldl/master
Mark test as complete at teardown.
2 parents a23f572 + c79a98c commit e83aae6

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
and ``EachScheduling`` implementations. Note that required scheduler class public
1111
API may change in next ``pytest-xdist`` versions.
1212

13+
- fix #124: xdist would mark test as complete after 'call' step. As a result,
14+
xdist could identify the wrong test as failing when test crashes at teardown.
15+
To address this issue, xdist now marks test as complete at teardown.
16+
1317
1.15.0
1418
------
1519

testing/acceptance_test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,32 @@ def test_noncrash():
437437
""")
438438
result = testdir.runpytest("-n2", p)
439439
result.stdout.fnmatch_lines([
440-
"*crashed*test_crash*", "*1 failed*1 passed*"
440+
"*crashed*::test_crash*", "*1 failed*1 passed*"
441+
])
442+
443+
444+
def test_crashing_item_teardown(testdir):
445+
p = testdir.makepyfile("""
446+
import py
447+
import pytest
448+
import os
449+
import time
450+
451+
@pytest.fixture
452+
def crash_fixture(request):
453+
def kill_me():
454+
py.process.kill(os.getpid())
455+
request.addfinalizer(kill_me)
456+
457+
def test_a(crash_fixture):
458+
pass
459+
460+
def test_b():
461+
pass
462+
""")
463+
result = testdir.runpytest("-n1", p)
464+
result.stdout.fnmatch_lines([
465+
"*crashed*::test_a*", "*1 failed*2 passed*"
441466
])
442467

443468

xdist/dsession.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ def slave_testreport(self, node, rep):
660660
If the node indicates it is finished with a test item, remove
661661
the item from the pending list in the scheduler.
662662
"""
663-
if rep.when == "call" or (rep.when == "setup" and not rep.passed):
663+
if rep.when == "teardown" or (rep.when == "setup" and not rep.passed):
664664
self.sched.mark_test_complete(node, rep.item_index, rep.duration)
665665
# self.report_line("testreport %s: %s" %(rep.id, rep.status))
666666
rep.node = node

0 commit comments

Comments
 (0)