Skip to content

Commit cd0ef41

Browse files
committed
Refactoring
1 parent 48c8e31 commit cd0ef41

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

tests/conftest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
import collections
2+
3+
import pytest
4+
5+
16
pytest_plugins = 'pytester'
7+
8+
9+
Call = collections.namedtuple('Call', field_names=('package', 'module', 'cls', 'name'))
10+
11+
12+
def _get_test_calls(result):
13+
"""
14+
Returns a tuple of test calls in the order they were made.
15+
"""
16+
calls = []
17+
18+
for c in result.reprec.getcalls('pytest_runtest_call'):
19+
calls.append(Call(
20+
package=c.item.module.__package__,
21+
module=c.item.module.__name__,
22+
cls=(c.item.module.__name__, c.item.cls.__name__) if c.item.cls else None,
23+
name=c.item.name,
24+
))
25+
return tuple(calls)
26+
27+
28+
@pytest.fixture
29+
def get_test_calls():
30+
"""
31+
Returns a function to get runtest calls out from testdir.pytestrun result object.
32+
"""
33+
return _get_test_calls

tests/test_actual_test_runs.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,6 @@
55
import pytest
66

77

8-
Call = collections.namedtuple('Call', field_names=('package', 'module', 'cls', 'name'))
9-
10-
11-
def get_runtest_call_sequence(result):
12-
"""
13-
Returns a tuple of names of test methods that were run
14-
in the order they were run.
15-
"""
16-
calls = []
17-
18-
for c in result.reprec.getcalls('pytest_runtest_call'):
19-
calls.append(Call(
20-
package=c.item.module.__package__,
21-
module=c.item.module.__name__,
22-
cls=(c.item.module.__name__, c.item.cls.__name__) if c.item.cls else None,
23-
name=c.item.name,
24-
))
25-
return tuple(calls)
26-
27-
288
@pytest.fixture
299
def tmp_tree_of_tests(testdir):
3010
"""
@@ -156,13 +136,13 @@ def inspect_attr(this_call, prev_call, attr_name):
156136

157137

158138
@pytest.mark.parametrize('bucket', ['class', 'module', 'package', 'global'])
159-
def test_it_works_with_actual_tests(tmp_tree_of_tests, bucket):
139+
def test_it_works_with_actual_tests(tmp_tree_of_tests, get_test_calls, bucket):
160140
sequences = set()
161141

162142
for x in range(5):
163143
result = tmp_tree_of_tests.runpytest('--random-order-bucket={}'.format(bucket), '--verbose')
164144
result.assert_outcomes(passed=14, failed=3)
165-
seq = get_runtest_call_sequence(result)
145+
seq = get_test_calls(result)
166146
check_call_sequence(seq, bucket=bucket)
167147
assert len(seq) == 17
168148
sequences.add(seq)

0 commit comments

Comments
 (0)