Skip to content

Commit a7e38c5

Browse files
authored
#7942 test_runner_xunit.py (#7964)
1 parent 3c7eb5a commit a7e38c5

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Anthony Sottile
3232
Anton Lodder
3333
Antony Lee
3434
Arel Cordero
35+
Ariel Pillemer
3536
Armin Rigo
3637
Aron Coyle
3738
Aron Curzon

testing/test_runner_xunit.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
from typing import List
33

44
import pytest
5+
from _pytest.pytester import Pytester
56

67

7-
def test_module_and_function_setup(testdir):
8-
reprec = testdir.inline_runsource(
8+
def test_module_and_function_setup(pytester: Pytester) -> None:
9+
reprec = pytester.inline_runsource(
910
"""
1011
modlevel = []
1112
def setup_module(module):
@@ -37,8 +38,8 @@ def test_module(self):
3738
assert rep.passed
3839

3940

40-
def test_module_setup_failure_no_teardown(testdir):
41-
reprec = testdir.inline_runsource(
41+
def test_module_setup_failure_no_teardown(pytester: Pytester) -> None:
42+
reprec = pytester.inline_runsource(
4243
"""
4344
values = []
4445
def setup_module(module):
@@ -57,8 +58,8 @@ def teardown_module(module):
5758
assert calls[0].item.module.values == [1]
5859

5960

60-
def test_setup_function_failure_no_teardown(testdir):
61-
reprec = testdir.inline_runsource(
61+
def test_setup_function_failure_no_teardown(pytester: Pytester) -> None:
62+
reprec = pytester.inline_runsource(
6263
"""
6364
modlevel = []
6465
def setup_function(function):
@@ -76,8 +77,8 @@ def test_func():
7677
assert calls[0].item.module.modlevel == [1]
7778

7879

79-
def test_class_setup(testdir):
80-
reprec = testdir.inline_runsource(
80+
def test_class_setup(pytester: Pytester) -> None:
81+
reprec = pytester.inline_runsource(
8182
"""
8283
class TestSimpleClassSetup(object):
8384
clslevel = []
@@ -102,8 +103,8 @@ def test_cleanup():
102103
reprec.assertoutcome(passed=1 + 2 + 1)
103104

104105

105-
def test_class_setup_failure_no_teardown(testdir):
106-
reprec = testdir.inline_runsource(
106+
def test_class_setup_failure_no_teardown(pytester: Pytester) -> None:
107+
reprec = pytester.inline_runsource(
107108
"""
108109
class TestSimpleClassSetup(object):
109110
clslevel = []
@@ -123,8 +124,8 @@ def test_cleanup():
123124
reprec.assertoutcome(failed=1, passed=1)
124125

125126

126-
def test_method_setup(testdir):
127-
reprec = testdir.inline_runsource(
127+
def test_method_setup(pytester: Pytester) -> None:
128+
reprec = pytester.inline_runsource(
128129
"""
129130
class TestSetupMethod(object):
130131
def setup_method(self, meth):
@@ -142,8 +143,8 @@ def test_other(self):
142143
reprec.assertoutcome(passed=2)
143144

144145

145-
def test_method_setup_failure_no_teardown(testdir):
146-
reprec = testdir.inline_runsource(
146+
def test_method_setup_failure_no_teardown(pytester: Pytester) -> None:
147+
reprec = pytester.inline_runsource(
147148
"""
148149
class TestMethodSetup(object):
149150
clslevel = []
@@ -164,8 +165,8 @@ def test_cleanup():
164165
reprec.assertoutcome(failed=1, passed=1)
165166

166167

167-
def test_method_setup_uses_fresh_instances(testdir):
168-
reprec = testdir.inline_runsource(
168+
def test_method_setup_uses_fresh_instances(pytester: Pytester) -> None:
169+
reprec = pytester.inline_runsource(
169170
"""
170171
class TestSelfState1(object):
171172
memory = []
@@ -179,8 +180,8 @@ def test_afterhello(self):
179180
reprec.assertoutcome(passed=2, failed=0)
180181

181182

182-
def test_setup_that_skips_calledagain(testdir):
183-
p = testdir.makepyfile(
183+
def test_setup_that_skips_calledagain(pytester: Pytester) -> None:
184+
p = pytester.makepyfile(
184185
"""
185186
import pytest
186187
def setup_module(mod):
@@ -191,12 +192,12 @@ def test_function2():
191192
pass
192193
"""
193194
)
194-
reprec = testdir.inline_run(p)
195+
reprec = pytester.inline_run(p)
195196
reprec.assertoutcome(skipped=2)
196197

197198

198-
def test_setup_fails_again_on_all_tests(testdir):
199-
p = testdir.makepyfile(
199+
def test_setup_fails_again_on_all_tests(pytester: Pytester) -> None:
200+
p = pytester.makepyfile(
200201
"""
201202
import pytest
202203
def setup_module(mod):
@@ -207,12 +208,12 @@ def test_function2():
207208
pass
208209
"""
209210
)
210-
reprec = testdir.inline_run(p)
211+
reprec = pytester.inline_run(p)
211212
reprec.assertoutcome(failed=2)
212213

213214

214-
def test_setup_funcarg_setup_when_outer_scope_fails(testdir):
215-
p = testdir.makepyfile(
215+
def test_setup_funcarg_setup_when_outer_scope_fails(pytester: Pytester) -> None:
216+
p = pytester.makepyfile(
216217
"""
217218
import pytest
218219
def setup_module(mod):
@@ -226,7 +227,7 @@ def test_function2(hello):
226227
pass
227228
"""
228229
)
229-
result = testdir.runpytest(p)
230+
result = pytester.runpytest(p)
230231
result.stdout.fnmatch_lines(
231232
[
232233
"*function1*",
@@ -241,7 +242,7 @@ def test_function2(hello):
241242

242243
@pytest.mark.parametrize("arg", ["", "arg"])
243244
def test_setup_teardown_function_level_with_optional_argument(
244-
testdir, monkeypatch, arg: str,
245+
pytester: Pytester, monkeypatch, arg: str,
245246
) -> None:
246247
"""Parameter to setup/teardown xunit-style functions parameter is now optional (#1728)."""
247248
import sys
@@ -250,7 +251,7 @@ def test_setup_teardown_function_level_with_optional_argument(
250251
monkeypatch.setattr(
251252
sys, "trace_setups_teardowns", trace_setups_teardowns, raising=False
252253
)
253-
p = testdir.makepyfile(
254+
p = pytester.makepyfile(
254255
"""
255256
import pytest
256257
import sys
@@ -276,7 +277,7 @@ def test_method_2(self): pass
276277
arg=arg
277278
)
278279
)
279-
result = testdir.inline_run(p)
280+
result = pytester.inline_run(p)
280281
result.assertoutcome(passed=4)
281282

282283
expected = [

0 commit comments

Comments
 (0)