From b79eff065ebbd3dd1c20cb06eb76cb6707a0c8d3 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 11 Feb 2022 12:20:42 -0300 Subject: [PATCH] Enable testing with Python 3.11 (#9511) --- .github/workflows/main.yml | 10 ++++++++++ testing/test_assertion.py | 16 +++++++++++----- testing/test_compat.py | 2 ++ testing/test_doctest.py | 2 ++ testing/test_main.py | 21 +++++++++++++++++++-- testing/test_pytester.py | 4 ++-- tox.ini | 1 + 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c53ab23d17..a69b905683b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -37,6 +37,7 @@ jobs: "windows-py38", "windows-py39", "windows-py310", + "windows-py311", "ubuntu-py37", "ubuntu-py37-pluggy", @@ -44,6 +45,7 @@ jobs: "ubuntu-py38", "ubuntu-py39", "ubuntu-py310", + "ubuntu-py311", "ubuntu-pypy3", "macos-py37", @@ -78,6 +80,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-py37" python: "3.7" @@ -104,6 +110,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 diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 317a2beb388..d57cc26a350 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1026,7 +1026,7 @@ def __eq__(self, other): # pragma: no cover assert lines is None def test_attrs_with_custom_eq(self) -> None: - @attr.define + @attr.define(slots=False) class SimpleDataObject: field_a = attr.ib() @@ -1648,7 +1648,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): @@ -1659,9 +1659,15 @@ def test_raising_repr(): """ ) result = pytester.runpytest() - result.stdout.fnmatch_lines( - ["E AssertionError: "] - ) + if sys.version_info >= (3, 11): + # python 3.11 has native support for un-str-able exceptions + result.stdout.fnmatch_lines( + ["E AssertionError: "] + ) + else: + result.stdout.fnmatch_lines( + ["E AssertionError: "] + ) def test_issue_1944(pytester: Pytester) -> None: diff --git a/testing/test_compat.py b/testing/test_compat.py index 88f0f33efc2..8a80fd625dc 100644 --- a/testing/test_compat.py +++ b/testing/test_compat.py @@ -1,4 +1,5 @@ import enum +import sys from functools import partial from functools import wraps from typing import TYPE_CHECKING @@ -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( """ diff --git a/testing/test_doctest.py b/testing/test_doctest.py index c2c83272079..67b8ccdb7ec 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -1,4 +1,5 @@ import inspect +import sys import textwrap from pathlib import Path from typing import Callable @@ -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 "", line 1, in ', "ZeroDivisionError: division by zero", "*/test_doctest_unexpected_exception.txt:2: UnexpectedException", diff --git a/testing/test_main.py b/testing/test_main.py index 926715a8c47..2df51bb7bb9 100644 --- a/testing/test_main.py +++ b/testing/test_main.py @@ -1,6 +1,7 @@ import argparse import os import re +import sys from pathlib import Path from typing import Optional @@ -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: diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 9f7cf42b77c..049f8b22d81 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -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) == "" ) diff --git a/tox.ini b/tox.ini index a1f4cab00e0..93c390ffc57 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ envlist = py38 py39 py310 + py311 pypy3 py37-{pexpect,xdist,unittestextras,numpy,pluggymain} doctesting