Skip to content

Commit b79eff0

Browse files
authored
Enable testing with Python 3.11 (#9511)
1 parent 6828ec2 commit b79eff0

File tree

7 files changed

+47
-9
lines changed

7 files changed

+47
-9
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ jobs:
3737
"windows-py38",
3838
"windows-py39",
3939
"windows-py310",
40+
"windows-py311",
4041

4142
"ubuntu-py37",
4243
"ubuntu-py37-pluggy",
4344
"ubuntu-py37-freeze",
4445
"ubuntu-py38",
4546
"ubuntu-py39",
4647
"ubuntu-py310",
48+
"ubuntu-py311",
4749
"ubuntu-pypy3",
4850

4951
"macos-py37",
@@ -78,6 +80,10 @@ jobs:
7880
python: "3.10"
7981
os: windows-latest
8082
tox_env: "py310-xdist"
83+
- name: "windows-py311"
84+
python: "3.11-dev"
85+
os: windows-latest
86+
tox_env: "py311"
8187

8288
- name: "ubuntu-py37"
8389
python: "3.7"
@@ -104,6 +110,10 @@ jobs:
104110
python: "3.10"
105111
os: ubuntu-latest
106112
tox_env: "py310-xdist"
113+
- name: "ubuntu-py311"
114+
python: "3.11-dev"
115+
os: ubuntu-latest
116+
tox_env: "py311"
107117
- name: "ubuntu-pypy3"
108118
python: "pypy-3.7"
109119
os: ubuntu-latest

testing/test_assertion.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ def __eq__(self, other): # pragma: no cover
10261026
assert lines is None
10271027

10281028
def test_attrs_with_custom_eq(self) -> None:
1029-
@attr.define
1029+
@attr.define(slots=False)
10301030
class SimpleDataObject:
10311031
field_a = attr.ib()
10321032

@@ -1648,7 +1648,7 @@ def test_raise_assertion_error():
16481648
)
16491649

16501650

1651-
def test_raise_assertion_error_raisin_repr(pytester: Pytester) -> None:
1651+
def test_raise_assertion_error_raising_repr(pytester: Pytester) -> None:
16521652
pytester.makepyfile(
16531653
"""
16541654
class RaisingRepr(object):
@@ -1659,9 +1659,15 @@ def test_raising_repr():
16591659
"""
16601660
)
16611661
result = pytester.runpytest()
1662-
result.stdout.fnmatch_lines(
1663-
["E AssertionError: <unprintable AssertionError object>"]
1664-
)
1662+
if sys.version_info >= (3, 11):
1663+
# python 3.11 has native support for un-str-able exceptions
1664+
result.stdout.fnmatch_lines(
1665+
["E AssertionError: <exception str() failed>"]
1666+
)
1667+
else:
1668+
result.stdout.fnmatch_lines(
1669+
["E AssertionError: <unprintable AssertionError object>"]
1670+
)
16651671

16661672

16671673
def test_issue_1944(pytester: Pytester) -> None:

testing/test_compat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import enum
2+
import sys
23
from functools import partial
34
from functools import wraps
45
from typing import TYPE_CHECKING
@@ -91,6 +92,7 @@ def foo(x):
9192
assert get_real_func(partial(foo)) is foo
9293

9394

95+
@pytest.mark.skipif(sys.version_info >= (3, 11), reason="couroutine removed")
9496
def test_is_generator_asyncio(pytester: Pytester) -> None:
9597
pytester.makepyfile(
9698
"""

testing/test_doctest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
import sys
23
import textwrap
34
from pathlib import Path
45
from typing import Callable
@@ -200,6 +201,7 @@ def test_doctest_unexpected_exception(self, pytester: Pytester):
200201
"Traceback (most recent call last):",
201202
' File "*/doctest.py", line *, in __run',
202203
" *",
204+
*((" *^^^^*",) if sys.version_info >= (3, 11) else ()),
203205
' File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>',
204206
"ZeroDivisionError: division by zero",
205207
"*/test_doctest_unexpected_exception.txt:2: UnexpectedException",

testing/test_main.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import argparse
22
import os
33
import re
4+
import sys
45
from pathlib import Path
56
from typing import Optional
67

@@ -44,16 +45,32 @@ def pytest_internalerror(excrepr, excinfo):
4445
assert result.ret == ExitCode.INTERNAL_ERROR
4546
assert result.stdout.lines[0] == "INTERNALERROR> Traceback (most recent call last):"
4647

48+
end_lines = (
49+
result.stdout.lines[-4:]
50+
if sys.version_info >= (3, 11)
51+
else result.stdout.lines[-3:]
52+
)
53+
4754
if exc == SystemExit:
48-
assert result.stdout.lines[-3:] == [
55+
assert end_lines == [
4956
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
5057
'INTERNALERROR> raise SystemExit("boom")',
58+
*(
59+
("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
60+
if sys.version_info >= (3, 11)
61+
else ()
62+
),
5163
"INTERNALERROR> SystemExit: boom",
5264
]
5365
else:
54-
assert result.stdout.lines[-3:] == [
66+
assert end_lines == [
5567
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
5668
'INTERNALERROR> raise ValueError("boom")',
69+
*(
70+
("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
71+
if sys.version_info >= (3, 11)
72+
else ()
73+
),
5774
"INTERNALERROR> ValueError: boom",
5875
]
5976
if returncode is False:

testing/test_pytester.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,8 @@ def test_run_result_repr() -> None:
743743

744744
# known exit code
745745
r = pytester_mod.RunResult(1, outlines, errlines, duration=0.5)
746-
assert (
747-
repr(r) == "<RunResult ret=ExitCode.TESTS_FAILED len(stdout.lines)=3"
746+
assert repr(r) == (
747+
f"<RunResult ret={str(pytest.ExitCode.TESTS_FAILED)} len(stdout.lines)=3"
748748
" len(stderr.lines)=4 duration=0.50s>"
749749
)
750750

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ envlist =
88
py38
99
py39
1010
py310
11+
py311
1112
pypy3
1213
py37-{pexpect,xdist,unittestextras,numpy,pluggymain}
1314
doctesting

0 commit comments

Comments
 (0)