Skip to content

Commit 6835cf4

Browse files
committed
Remove dependency on the pytest version in tests of documentation
examples
1 parent 101efbc commit 6835cf4

File tree

5 files changed

+73
-49
lines changed

5 files changed

+73
-49
lines changed

tests/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import packaging.version
21
from pathlib import Path
32
import pytest
43

54
pytest_plugins = "pytester"
65

76
example_dir = (Path(__file__).parent / "../doc/examples").resolve()
87

9-
def require_pytest_version(minversion):
10-
pytest_version = packaging.version.parse(pytest.__version__)
11-
if pytest_version < packaging.version.parse(minversion):
12-
pytest.skip("need pytest version %s or newer" % minversion,
13-
allow_module_level=True)
14-
158
def get_example(fname):
169
path = example_dir / fname
1710
assert path.is_file()

tests/test_09_examples_advanced.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"""
33

44
import pytest
5-
from conftest import get_example, require_pytest_version
6-
7-
require_pytest_version("4.2.0")
5+
from conftest import get_example
86

97

108
def test_dyn_parametrized(ctestdir):
@@ -13,7 +11,10 @@ def test_dyn_parametrized(ctestdir):
1311
with get_example("dyn-parametrized.py").open("rt") as f:
1412
ctestdir.makepyfile(f.read())
1513
result = ctestdir.runpytest("--verbose")
16-
result.assert_outcomes(passed=11, skipped=1, failed=0, xfailed=1)
14+
try:
15+
result.assert_outcomes(passed=11, skipped=1, failed=0, xfailed=1)
16+
except TypeError:
17+
result.assert_outcomes(passed=11, skipped=1, failed=0)
1718
result.stdout.re_match_lines(r"""
1819
.*::test_child\[c0\] PASSED
1920
.*::test_child\[c1\] PASSED
@@ -22,7 +23,7 @@ def test_dyn_parametrized(ctestdir):
2223
.*::test_child\[c4\] PASSED
2324
.*::test_child\[c5\] PASSED
2425
.*::test_child\[c6\] PASSED
25-
.*::test_child\[c7\] XFAIL(?:\s+\(.*\))?
26+
.*::test_child\[c7\] (?:XFAIL(?:\s+\(.*\))?|xfail)
2627
.*::test_child\[c8\] PASSED
2728
.*::test_parent\[p0\] PASSED
2829
.*::test_parent\[p1\] PASSED
@@ -37,7 +38,10 @@ def test_group_fixture1(ctestdir):
3738
with get_example("group-fixture.py").open("rt") as f:
3839
ctestdir.makepyfile(f.read())
3940
result = ctestdir.runpytest("--verbose")
40-
result.assert_outcomes(passed=16, skipped=1, failed=0, xfailed=1)
41+
try:
42+
result.assert_outcomes(passed=16, skipped=1, failed=0, xfailed=1)
43+
except TypeError:
44+
result.assert_outcomes(passed=16, skipped=1, failed=0)
4145
result.stdout.re_match_lines(r"""
4246
.*::test_a\[1\] PASSED
4347
.*::test_b\[1\] PASSED
@@ -51,7 +55,7 @@ def test_group_fixture1(ctestdir):
5155
.*::test_b\[5\] PASSED
5256
.*::test_a\[6\] PASSED
5357
.*::test_b\[6\] PASSED
54-
.*::test_a\[7\] XFAIL(?:\s+\(.*\))?
58+
.*::test_a\[7\] (?:XFAIL(?:\s+\(.*\))?|xfail)
5559
.*::test_b\[7\] SKIPPED(?:\s+\(.*\))?
5660
.*::test_a\[8\] PASSED
5761
.*::test_b\[8\] PASSED
@@ -66,7 +70,10 @@ def test_group_fixture2(ctestdir):
6670
with get_example("group-fixture2.py").open("rt") as f:
6771
ctestdir.makepyfile(f.read())
6872
result = ctestdir.runpytest("--verbose")
69-
result.assert_outcomes(passed=24, skipped=2, failed=0, xfailed=1)
73+
try:
74+
result.assert_outcomes(passed=24, skipped=2, failed=0, xfailed=1)
75+
except TypeError:
76+
result.assert_outcomes(passed=24, skipped=2, failed=0)
7077
result.stdout.re_match_lines(r"""
7178
.*::test_a\[1\] PASSED
7279
.*::test_b\[1\] PASSED
@@ -86,7 +93,7 @@ def test_group_fixture2(ctestdir):
8693
.*::test_a\[6\] PASSED
8794
.*::test_b\[6\] PASSED
8895
.*::test_c\[6\] PASSED
89-
.*::test_a\[7\] XFAIL(?:\s+\(.*\))?
96+
.*::test_a\[7\] (?:XFAIL(?:\s+\(.*\))?|xfail)
9097
.*::test_b\[7\] SKIPPED(?:\s+\(.*\))?
9198
.*::test_c\[7\] SKIPPED(?:\s+\(.*\))?
9299
.*::test_a\[8\] PASSED
@@ -104,7 +111,10 @@ def test_all_params(ctestdir):
104111
with get_example("all_params.py").open("rt") as f:
105112
ctestdir.makepyfile(f.read())
106113
result = ctestdir.runpytest("--verbose")
107-
result.assert_outcomes(passed=20, skipped=3, failed=0, xfailed=3)
114+
try:
115+
result.assert_outcomes(passed=20, skipped=3, failed=0, xfailed=3)
116+
except TypeError:
117+
result.assert_outcomes(passed=20, skipped=3, failed=0)
108118
result.stdout.re_match_lines(r"""
109119
.*::test_a\[0\] PASSED
110120
.*::test_a\[1\] PASSED
@@ -119,17 +129,17 @@ def test_all_params(ctestdir):
119129
.*::test_a\[10\] PASSED
120130
.*::test_a\[11\] PASSED
121131
.*::test_a\[12\] PASSED
122-
.*::test_a\[13\] XFAIL(?:\s+\(.*\))?
132+
.*::test_a\[13\] (?:XFAIL(?:\s+\(.*\))?|xfail)
123133
.*::test_a\[14\] PASSED
124134
.*::test_a\[15\] PASSED
125135
.*::test_a\[16\] PASSED
126136
.*::test_b SKIPPED(?:\s+\(.*\))?
127137
.*::test_c\[0-2\] PASSED
128138
.*::test_c\[2-3\] PASSED
129139
.*::test_c\[4-4\] PASSED
130-
.*::test_c\[6-5\] XFAIL(?:\s+\(.*\))?
140+
.*::test_c\[6-5\] (?:XFAIL(?:\s+\(.*\))?|xfail)
131141
.*::test_d SKIPPED(?:\s+\(.*\))?
132142
.*::test_e\[abc\] PASSED
133-
.*::test_e\[def\] XFAIL(?:\s+\(.*\))?
143+
.*::test_e\[def\] (?:XFAIL(?:\s+\(.*\))?|xfail)
134144
.*::test_f SKIPPED(?:\s+\(.*\))?
135145
""")

tests/test_09_examples_names.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"""
33

44
import pytest
5-
from conftest import get_example, require_pytest_version
6-
7-
require_pytest_version("4.2.0")
5+
from conftest import get_example
86

97

108
def test_nodeid(ctestdir):
@@ -13,12 +11,15 @@ def test_nodeid(ctestdir):
1311
with get_example("nodeid.py").open("rt") as f:
1412
ctestdir.makepyfile(f.read())
1513
result = ctestdir.runpytest("--verbose")
16-
result.assert_outcomes(passed=6, skipped=0, failed=0, xfailed=1)
14+
try:
15+
result.assert_outcomes(passed=6, skipped=0, failed=0, xfailed=1)
16+
except TypeError:
17+
result.assert_outcomes(passed=6, skipped=0, failed=0)
1718
result.stdout.re_match_lines(r"""
1819
.*::test_a PASSED
1920
.*::test_b\[7-True\] PASSED
2021
.*::test_b\[0-False\] PASSED
21-
.*::test_b\[-1-False\] XFAIL(?:\s+\(.*\))?
22+
.*::test_b\[-1-False\] (?:XFAIL(?:\s+\(.*\))?|xfail)
2223
.*::TestClass::test_c PASSED
2324
.*::TestClass::test_d\[order\] PASSED
2425
.*::TestClass::test_d\[disorder\] PASSED

tests/test_09_examples_scope.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
from pathlib import Path
55
import pytest
6-
from conftest import get_example, require_pytest_version
7-
8-
require_pytest_version("4.2.0")
6+
from conftest import get_example
97

108

119
def test_scope_module(ctestdir):
@@ -14,9 +12,12 @@ def test_scope_module(ctestdir):
1412
with get_example("scope_module.py").open("rt") as f:
1513
ctestdir.makepyfile(f.read())
1614
result = ctestdir.runpytest("--verbose")
17-
result.assert_outcomes(passed=2, skipped=2, failed=0, xfailed=1)
15+
try:
16+
result.assert_outcomes(passed=2, skipped=2, failed=0, xfailed=1)
17+
except TypeError:
18+
result.assert_outcomes(passed=2, skipped=2, failed=0)
1819
result.stdout.re_match_lines(r"""
19-
.*::test_a XFAIL(?:\s+\(.*\))?
20+
.*::test_a (?:XFAIL(?:\s+\(.*\))?|xfail)
2021
.*::test_b PASSED
2122
.*::test_c SKIPPED(?:\s+\(.*\))?
2223
.*::test_d PASSED
@@ -36,13 +37,16 @@ def test_scope_session(ctestdir):
3637
with (subdir / "test_mod_02.py").open("wt") as df:
3738
df.write(sf.read())
3839
result = ctestdir.runpytest("--verbose")
39-
result.assert_outcomes(passed=5, skipped=1, failed=0, xfailed=2)
40+
try:
41+
result.assert_outcomes(passed=5, skipped=1, failed=0, xfailed=2)
42+
except TypeError:
43+
result.assert_outcomes(passed=5, skipped=1, failed=0)
4044
result.stdout.re_match_lines(r"""
4145
tests/test_mod_01.py::test_a PASSED
42-
tests/test_mod_01.py::test_b XFAIL(?:\s+\(.*\))?
46+
tests/test_mod_01.py::test_b (?:XFAIL(?:\s+\(.*\))?|xfail)
4347
tests/test_mod_01.py::test_c PASSED
4448
tests/test_mod_01.py::TestClass::test_b PASSED
45-
tests/test_mod_02.py::test_a XFAIL(?:\s+\(.*\))?
49+
tests/test_mod_02.py::test_a (?:XFAIL(?:\s+\(.*\))?|xfail)
4650
tests/test_mod_02.py::test_e PASSED
4751
tests/test_mod_02.py::test_f SKIPPED(?:\s+\(.*\))?
4852
tests/test_mod_02.py::test_g PASSED
@@ -55,9 +59,12 @@ def test_scope_class(ctestdir):
5559
with get_example("scope_class.py").open("rt") as f:
5660
ctestdir.makepyfile(f.read())
5761
result = ctestdir.runpytest("--verbose")
58-
result.assert_outcomes(passed=3, skipped=2, failed=0, xfailed=1)
62+
try:
63+
result.assert_outcomes(passed=3, skipped=2, failed=0, xfailed=1)
64+
except TypeError:
65+
result.assert_outcomes(passed=3, skipped=2, failed=0)
5966
result.stdout.re_match_lines(r"""
60-
.*::test_a XFAIL(?:\s+\(.*\))?
67+
.*::test_a (?:XFAIL(?:\s+\(.*\))?|xfail)
6168
.*::TestClass1::test_b PASSED
6269
.*::TestClass2::test_a PASSED
6370
.*::TestClass2::test_c SKIPPED(?:\s+\(.*\))?

tests/test_09_examples_usage.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
"""
33

44
import pytest
5-
from conftest import get_example, require_pytest_version
6-
7-
require_pytest_version("4.2.0")
5+
from conftest import get_example
86

97

108
def test_basic(ctestdir):
@@ -13,9 +11,12 @@ def test_basic(ctestdir):
1311
with get_example("basic.py").open("rt") as f:
1412
ctestdir.makepyfile(f.read())
1513
result = ctestdir.runpytest("--verbose")
16-
result.assert_outcomes(passed=2, skipped=2, failed=0, xfailed=1)
14+
try:
15+
result.assert_outcomes(passed=2, skipped=2, failed=0, xfailed=1)
16+
except TypeError:
17+
result.assert_outcomes(passed=2, skipped=2, failed=0)
1718
result.stdout.re_match_lines(r"""
18-
.*::test_a XFAIL(?:\s+\(.*\))?
19+
.*::test_a (?:XFAIL(?:\s+\(.*\))?|xfail)
1920
.*::test_b PASSED
2021
.*::test_c SKIPPED(?:\s+\(.*\))?
2122
.*::test_d PASSED
@@ -29,9 +30,12 @@ def test_named(ctestdir):
2930
with get_example("named.py").open("rt") as f:
3031
ctestdir.makepyfile(f.read())
3132
result = ctestdir.runpytest("--verbose")
32-
result.assert_outcomes(passed=2, skipped=2, failed=0, xfailed=1)
33+
try:
34+
result.assert_outcomes(passed=2, skipped=2, failed=0, xfailed=1)
35+
except TypeError:
36+
result.assert_outcomes(passed=2, skipped=2, failed=0)
3337
result.stdout.re_match_lines(r"""
34-
.*::test_a XFAIL(?:\s+\(.*\))?
38+
.*::test_a (?:XFAIL(?:\s+\(.*\))?|xfail)
3539
.*::test_b PASSED
3640
.*::test_c SKIPPED(?:\s+\(.*\))?
3741
.*::test_d PASSED
@@ -45,14 +49,17 @@ def test_testclass(ctestdir):
4549
with get_example("testclass.py").open("rt") as f:
4650
ctestdir.makepyfile(f.read())
4751
result = ctestdir.runpytest("--verbose")
48-
result.assert_outcomes(passed=4, skipped=4, failed=0, xfailed=2)
52+
try:
53+
result.assert_outcomes(passed=4, skipped=4, failed=0, xfailed=2)
54+
except TypeError:
55+
result.assert_outcomes(passed=4, skipped=4, failed=0)
4956
result.stdout.re_match_lines(r"""
50-
.*::TestClass::test_a XFAIL(?:\s+\(.*\))?
57+
.*::TestClass::test_a (?:XFAIL(?:\s+\(.*\))?|xfail)
5158
.*::TestClass::test_b PASSED
5259
.*::TestClass::test_c SKIPPED(?:\s+\(.*\))?
5360
.*::TestClass::test_d PASSED
5461
.*::TestClass::test_e SKIPPED(?:\s+\(.*\))?
55-
.*::TestClassNamed::test_a XFAIL(?:\s+\(.*\))?
62+
.*::TestClassNamed::test_a (?:XFAIL(?:\s+\(.*\))?|xfail)
5663
.*::TestClassNamed::test_b PASSED
5764
.*::TestClassNamed::test_c SKIPPED(?:\s+\(.*\))?
5865
.*::TestClassNamed::test_d PASSED
@@ -66,10 +73,13 @@ def test_parametrized(ctestdir):
6673
with get_example("parametrized.py").open("rt") as f:
6774
ctestdir.makepyfile(f.read())
6875
result = ctestdir.runpytest("--verbose")
69-
result.assert_outcomes(passed=7, skipped=5, failed=0, xfailed=1)
76+
try:
77+
result.assert_outcomes(passed=7, skipped=5, failed=0, xfailed=1)
78+
except TypeError:
79+
result.assert_outcomes(passed=7, skipped=5, failed=0)
7080
result.stdout.re_match_lines(r"""
7181
.*::test_a\[0-0\] PASSED
72-
.*::test_a\[0-1\] XFAIL(?:\s+\(.*\))?
82+
.*::test_a\[0-1\] (?:XFAIL(?:\s+\(.*\))?|xfail)
7383
.*::test_a\[1-0\] PASSED
7484
.*::test_a\[1-1\] PASSED
7585
.*::test_b\[1-2\] SKIPPED(?:\s+\(.*\))?
@@ -90,10 +100,13 @@ def test_runtime(ctestdir):
90100
with get_example("runtime.py").open("rt") as f:
91101
ctestdir.makepyfile(f.read())
92102
result = ctestdir.runpytest("--verbose")
93-
result.assert_outcomes(passed=1, skipped=2, failed=0, xfailed=1)
103+
try:
104+
result.assert_outcomes(passed=1, skipped=2, failed=0, xfailed=1)
105+
except TypeError:
106+
result.assert_outcomes(passed=1, skipped=2, failed=0)
94107
result.stdout.re_match_lines(r"""
95108
.*::test_a PASSED
96-
.*::test_b XFAIL(?:\s+\(.*\))?
109+
.*::test_b (?:XFAIL(?:\s+\(.*\))?|xfail)
97110
.*::test_c SKIPPED(?:\s+\(.*\))?
98111
.*::test_d SKIPPED(?:\s+\(.*\))?
99112
""")

0 commit comments

Comments
 (0)