Skip to content

Commit

Permalink
Enable testing with Python 3.11 (#9511)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Feb 11, 2022
1 parent ac37b1b commit 6ca733e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
"windows-py38",
"windows-py39",
"windows-py310",
"windows-py311",

"ubuntu-py36",
"ubuntu-py37",
Expand All @@ -45,6 +46,7 @@ jobs:
"ubuntu-py38",
"ubuntu-py39",
"ubuntu-py310",
"ubuntu-py311",
"ubuntu-pypy3",

"macos-py37",
Expand Down Expand Up @@ -81,6 +83,10 @@ jobs:
python: "3.10"
os: windows-latest
tox_env: "py310-xdist"
- name: "windows-py311"
python: "3.11-dev"
os: windows-latest
tox_env: "py311"

- name: "ubuntu-py36"
python: "3.6"
Expand Down Expand Up @@ -111,6 +117,10 @@ jobs:
python: "3.10"
os: ubuntu-latest
tox_env: "py310-xdist"
- name: "ubuntu-py311"
python: "3.11-dev"
os: ubuntu-latest
tox_env: "py311"
- name: "ubuntu-pypy3"
python: "pypy-3.7"
os: ubuntu-latest
Expand Down
14 changes: 10 additions & 4 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ def test_raise_assertion_error():
)


def test_raise_assertion_error_raisin_repr(pytester: Pytester) -> None:
def test_raise_assertion_error_raising_repr(pytester: Pytester) -> None:
pytester.makepyfile(
"""
class RaisingRepr(object):
Expand All @@ -1627,9 +1627,15 @@ def test_raising_repr():
"""
)
result = pytester.runpytest()
result.stdout.fnmatch_lines(
["E AssertionError: <unprintable AssertionError object>"]
)
if sys.version_info >= (3, 11):
# python 3.11 has native support for un-str-able exceptions
result.stdout.fnmatch_lines(
["E AssertionError: <exception str() failed>"]
)
else:
result.stdout.fnmatch_lines(
["E AssertionError: <unprintable AssertionError object>"]
)


def test_issue_1944(pytester: Pytester) -> None:
Expand Down
2 changes: 2 additions & 0 deletions testing/test_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import sys
from functools import partial
from functools import wraps
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -91,6 +92,7 @@ def foo(x):
assert get_real_func(partial(foo)) is foo


@pytest.mark.skipif(sys.version_info >= (3, 11), reason="couroutine removed")
def test_is_generator_asyncio(pytester: Pytester) -> None:
pytester.makepyfile(
"""
Expand Down
2 changes: 2 additions & 0 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import sys
import textwrap
from pathlib import Path
from typing import Callable
Expand Down Expand Up @@ -200,6 +201,7 @@ def test_doctest_unexpected_exception(self, pytester: Pytester):
"Traceback (most recent call last):",
' File "*/doctest.py", line *, in __run',
" *",
*((" *^^^^*",) if sys.version_info >= (3, 11) else ()),
' File "<doctest test_doctest_unexpected_exception.txt[1]>", line 1, in <module>',
"ZeroDivisionError: division by zero",
"*/test_doctest_unexpected_exception.txt:2: UnexpectedException",
Expand Down
21 changes: 19 additions & 2 deletions testing/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import os
import re
import sys
from pathlib import Path
from typing import Optional

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

end_lines = (
result.stdout.lines[-4:]
if sys.version_info >= (3, 11)
else result.stdout.lines[-3:]
)

if exc == SystemExit:
assert result.stdout.lines[-3:] == [
assert end_lines == [
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
'INTERNALERROR> raise SystemExit("boom")',
*(
("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
if sys.version_info >= (3, 11)
else ()
),
"INTERNALERROR> SystemExit: boom",
]
else:
assert result.stdout.lines[-3:] == [
assert end_lines == [
f'INTERNALERROR> File "{c1}", line 4, in pytest_sessionstart',
'INTERNALERROR> raise ValueError("boom")',
*(
("INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^",)
if sys.version_info >= (3, 11)
else ()
),
"INTERNALERROR> ValueError: boom",
]
if returncode is False:
Expand Down
4 changes: 2 additions & 2 deletions testing/test_pytester.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ def test_run_result_repr() -> None:

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

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ envlist =
py38
py39
py310
py311
pypy3
py37-{pexpect,xdist,unittestextras,numpy,pluggymain}
doctesting
Expand Down

0 comments on commit 6ca733e

Please sign in to comment.