-
Notifications
You must be signed in to change notification settings - Fork 14
/
test_xdist_handling.py
69 lines (56 loc) · 1.69 KB
/
test_xdist_handling.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from textwrap import dedent
import pytest
import pytest_order
def test_xdist_ordering(tmpdir):
testname = str(tmpdir.join("first_test.py"))
with open(testname, "w") as fi:
fi.write(
dedent(
"""
import pytest
val = 1
@pytest.mark.order("second")
def test_second_integer():
global val
assert val == 2
val += 1
def test_last_integer():
assert val == 3
@pytest.mark.order("first")
def test_first_integer():
global val
assert val == 1
val += 1
"""
)
)
testname = str(tmpdir.join("second_test.py"))
with open(testname, "w") as fi:
fi.write(
dedent(
"""
import pytest
val = "frog"
@pytest.mark.order("second")
def test_second_string():
global val
assert val == "goat"
val = "fish"
def test_last_string():
assert val == "fish"
@pytest.mark.order("first")
def test_first_string():
global val
assert val == "frog"
val = "goat"
"""
)
)
# With `loadfile`, the tests should pass
args = ["-n3", "--dist=loadfile", f"--rootdir={tmpdir}", str(tmpdir)]
ret = pytest.main(args, [pytest_order])
assert ret == 0
# Without `loadfile`, the tests should fail
args = ["-n3", f"--rootdir={tmpdir}", str(tmpdir)]
ret = pytest.main(args, [pytest_order])
assert ret == 1