MCPcopy Create free account
hub / github.com/pytest-dev/pytest / stepwise_pytester

Function stepwise_pytester

testing/test_stepwise.py:7–54  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

5
6@pytest.fixture
7def stepwise_pytester(pytester: Pytester) -> Pytester:
8 # Rather than having to modify our testfile between tests, we introduce
9 # a flag for whether or not the second test should fail.
10 pytester.makeconftest(
11 """
12def pytest_addoption(parser):
13 group = parser.getgroup('general')
14 group.addoption('--fail', action='store_true', dest='fail')
15 group.addoption('--fail-last', action='store_true', dest='fail_last')
16"""
17 )
18
19 # Create a simple test suite.
20 pytester.makepyfile(
21 test_a="""
22def test_success_before_fail():
23 assert 1
24
25def test_fail_on_flag(request):
26 assert not request.config.getvalue('fail')
27
28def test_success_after_fail():
29 assert 1
30
31def test_fail_last_on_flag(request):
32 assert not request.config.getvalue('fail_last')
33
34def test_success_after_last_fail():
35 assert 1
36"""
37 )
38
39 pytester.makepyfile(
40 test_b="""
41def test_success():
42 assert 1
43"""
44 )
45
46 # customize cache directory so we don't use the tox's cache directory, which makes tests in this module flaky
47 pytester.makeini(
48 """
49 [pytest]
50 cache_dir = .cache
51 """
52 )
53
54 return pytester
55
56
57@pytest.fixture

Callers

nothing calls this directly

Calls 3

makeconftestMethod · 0.45
makepyfileMethod · 0.45
makeiniMethod · 0.45

Tested by

no test coverage detected