forked from mark-adams/pytest-test-groups
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pytest.py
73 lines (63 loc) · 2.34 KB
/
test_pytest.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
70
71
72
73
pytest_plugins = ['pytester']
def test_group_runs_appropriate_tests(testdir):
testdir.makepyfile("""
def test_x(): pass
def test_y(): pass
def test_z(): pass
""")
result = testdir.runpytest_subprocess('--test-group-count', '2', '--test-group', '1')
result.assert_outcomes(passed=2)
result.stdout.fnmatch_lines([
'Running test group #1 (2 tests)'
])
result = testdir.runpytest_subprocess('--test-group-count', '2', '--test-group', '2')
result.assert_outcomes(passed=1)
result.stdout.fnmatch_lines([
'Running test group #2 (1 tests)'
])
def test_group_runs_all_test(testdir):
"""Given a large set of tests executed in random order, assert that all
tests are executed.
"""
testdir.makepyfile("""
def test_b(): pass
def test_c(): pass
def test_d(): pass
def test_e(): pass
def test_f(): pass
def test_g(): pass
def test_h(): pass
def test_i(): pass
def test_j(): pass
def test_k(): pass
def test_l(): pass
def test_m(): pass
def test_n(): pass
def test_o(): pass
def test_p(): pass
def test_q(): pass
def test_r(): pass
def test_s(): pass
def test_t(): pass
def test_u(): pass
def test_v(): pass
def test_w(): pass
def test_x(): pass
def test_y(): pass
def test_z(): pass
""")
result = testdir.inline_run('--test-group-count', '2',
'--test-group', '1',
'--test-group-random-seed', '5')
group_1 = [x.item.name for x in result.calls if x._name == 'pytest_runtest_call']
result.assertoutcome(passed=13)
result = testdir.inline_run('--test-group-count', '2',
'--test-group', '2',
'--test-group-random-seed', '5')
group_2 = [x.item.name for x in result.calls if x._name == 'pytest_runtest_call']
result.assertoutcome(passed=12)
result = testdir.inline_run('--test-group-count', '1',
'--test-group', '1',
'--test-group-random-seed', '5')
all_tests = [x.item.name for x in result.calls if x._name == 'pytest_runtest_call']
assert set(group_1 + group_2) == set(all_tests)