From 5076792b710801f21c74bb30a6303fb569616421 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 14 Jan 2022 11:37:29 -0300 Subject: [PATCH 01/10] Enable testing with Python 3.11 We should add Python 3.11 to our testing matrix in order to antecipate possible problems (even if we don't attempt to solve any of them right away). --- .github/workflows/main.yml | 10 ++++++++++ tox.ini | 1 + 2 files changed, 11 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2c53ab23d1..96f04ca640 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.0-alpha.3" + 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.0-alpha.3" + os: ubuntu-latest + tox_env: "py311" - name: "ubuntu-pypy3" python: "pypy-3.7" os: ubuntu-latest diff --git a/tox.ini b/tox.ini index a1f4cab00e..93c390ffc5 100644 --- a/tox.ini +++ b/tox.ini @@ -8,6 +8,7 @@ envlist = py38 py39 py310 + py311 pypy3 py37-{pexpect,xdist,unittestextras,numpy,pluggymain} doctesting From 316090eb5c753e0e0317e4b2c84d141eae8c005f Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 23 Jan 2022 13:52:44 -0500 Subject: [PATCH 02/10] python 3.11 fixes: enum repr changed --- testing/python/metafunc.py | 5 ++++- testing/test_pytester.py | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index b6ad4a8092..97678abce1 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -488,7 +488,10 @@ def test_idmaker_enum(self) -> None: result = IdMaker( ("a", "b"), [pytest.param(e.one, e.two)], None, None, None, None ).make_unique_parameterset_ids() - assert result == ["Foo.one-Foo.two"] + if sys.version_info >= (3, 11): + assert result == ["one-two"] + else: + assert result == ["Foo.one-Foo.two"] def test_idmaker_idfn(self) -> None: """#351""" diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 9f7cf42b77..d0ec1293ce 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -743,10 +743,16 @@ def test_run_result_repr() -> None: # known exit code r = pytester_mod.RunResult(1, outlines, errlines, duration=0.5) - assert ( - repr(r) == "" - ) + if sys.version_info >= (3, 11): + assert ( + repr(r) == "" + ) + else: + assert ( + repr(r) == "" + ) # unknown exit code: just the number r = pytester_mod.RunResult(99, outlines, errlines, duration=0.5) From 737688eeb9fe7c4a469c81aa0daae5259e08eabb Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 23 Jan 2022 13:54:00 -0500 Subject: [PATCH 03/10] python 3.11 fixes: traceback ^^^ helpers --- testing/test_doctest.py | 2 ++ testing/test_main.py | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/testing/test_doctest.py b/testing/test_doctest.py index c2c8327207..67b8ccdb7e 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 926715a8c4..2df51bb7bb 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: From 43d54c8b4220b53d5618b3b6b557aad778bbec31 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 23 Jan 2022 13:55:17 -0500 Subject: [PATCH 04/10] python 3.11 fixes: avoid attrs warning for setting cells RuntimeWarning: Running interpreter doesn't sufficiently support code object introspection. Some features like bare super() or accessing __class__ will not work with slotted classes. --- testing/test_assertion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 317a2beb38..ae053f137e 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() From 286a2bcadb75839caaffe53e8d98a607fb58233f Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 23 Jan 2022 13:55:48 -0500 Subject: [PATCH 05/10] python 3.11 fixes: native support for un-stringable exceptions --- testing/test_assertion.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index ae053f137e..d57cc26a35 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -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: From 923406254500f1e2eb9e2ba2429e36838b0cb23b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sun, 23 Jan 2022 13:56:10 -0500 Subject: [PATCH 06/10] python 3.11 fixes: coroutine was removed --- testing/test_compat.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testing/test_compat.py b/testing/test_compat.py index 88f0f33efc..8a80fd625d 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( """ From f9f470a6baa7e9a65ed6546e85d1456a5264af09 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 11 Feb 2022 05:37:07 -0800 Subject: [PATCH 07/10] Use 3.11 alpha 4 --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 96f04ca640..d5263d7711 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,7 +81,7 @@ jobs: os: windows-latest tox_env: "py310-xdist" - name: "windows-py311" - python: "3.11.0-alpha.3" + python: "3.11.0-alpha.4" os: windows-latest tox_env: "py311" @@ -111,7 +111,7 @@ jobs: os: ubuntu-latest tox_env: "py310-xdist" - name: "ubuntu-py311" - python: "3.11.0-alpha.3" + python: "3.11.0-alpha.4" os: ubuntu-latest tox_env: "py311" - name: "ubuntu-pypy3" From aa24533b88c997f521a3ff5c62258d6a27348e38 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 11 Feb 2022 11:17:16 -0300 Subject: [PATCH 08/10] Use 3.11-dev --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d5263d7711..a69b905683 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -81,7 +81,7 @@ jobs: os: windows-latest tox_env: "py310-xdist" - name: "windows-py311" - python: "3.11.0-alpha.4" + python: "3.11-dev" os: windows-latest tox_env: "py311" @@ -111,7 +111,7 @@ jobs: os: ubuntu-latest tox_env: "py310-xdist" - name: "ubuntu-py311" - python: "3.11.0-alpha.4" + python: "3.11-dev" os: ubuntu-latest tox_env: "py311" - name: "ubuntu-pypy3" From d18a29eb9ada73cee1e52a23be1cb3df57d5f0ed Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 11 Feb 2022 11:37:37 -0300 Subject: [PATCH 09/10] Revert "python 3.11 fixes: enum repr changed" This reverts commit 316090eb5c753e0e0317e4b2c84d141eae8c005f. --- testing/python/metafunc.py | 5 +---- testing/test_pytester.py | 14 ++++---------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 97678abce1..b6ad4a8092 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -488,10 +488,7 @@ def test_idmaker_enum(self) -> None: result = IdMaker( ("a", "b"), [pytest.param(e.one, e.two)], None, None, None, None ).make_unique_parameterset_ids() - if sys.version_info >= (3, 11): - assert result == ["one-two"] - else: - assert result == ["Foo.one-Foo.two"] + assert result == ["Foo.one-Foo.two"] def test_idmaker_idfn(self) -> None: """#351""" diff --git a/testing/test_pytester.py b/testing/test_pytester.py index d0ec1293ce..9f7cf42b77 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -743,16 +743,10 @@ def test_run_result_repr() -> None: # known exit code r = pytester_mod.RunResult(1, outlines, errlines, duration=0.5) - if sys.version_info >= (3, 11): - assert ( - repr(r) == "" - ) - else: - assert ( - repr(r) == "" - ) + assert ( + repr(r) == "" + ) # unknown exit code: just the number r = pytester_mod.RunResult(99, outlines, errlines, duration=0.5) From fd1ef0c527fbe52fc1d98b98f01a520ea0deae18 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 11 Feb 2022 12:02:50 -0300 Subject: [PATCH 10/10] Make test_run_result_repr independent from Enum repr --- testing/test_pytester.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 9f7cf42b77..049f8b22d8 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) == "" )