From f70899577557de2a66f71a202a8e8aadb2800e7c Mon Sep 17 00:00:00 2001 From: Richard Tibbles Date: Mon, 1 Jul 2024 15:24:58 -0700 Subject: [PATCH] Add Python 3.12 support. Update tests and test dependencies for Python 3.12. --- .github/workflows/tox.yml | 4 +-- pytest.ini | 2 ++ requirements/test.txt | 8 +++--- setup.py | 3 ++- tests/patch_pytest.py | 57 --------------------------------------- tests/pytest_3.10.patch | 38 -------------------------- tox.ini | 6 ++--- 7 files changed, 12 insertions(+), 106 deletions(-) delete mode 100644 tests/patch_pytest.py delete mode 100644 tests/pytest_3.10.patch diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 2f117030..d88ad176 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -22,7 +22,7 @@ jobs: strategy: max-parallel: 5 matrix: - python-version: [3.6, 3.7, 3.8, 3.9, '3.10', '3.11'] + python-version: [ 3.6, 3.7, 3.8, 3.9, '3.10', '3.11', '3.12' ] steps: - uses: actions/checkout@v2 @@ -54,7 +54,7 @@ jobs: strategy: max-parallel: 5 matrix: - python-version: [ 3.6, 3.7, 3.8, 3.9, '3.10', '3.11' ] + python-version: [ 3.6, 3.7, 3.8, 3.9, '3.10', '3.11', '3.12' ] steps: - uses: actions/checkout@v2 diff --git a/pytest.ini b/pytest.ini index ed6c86cd..75bc470f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,3 +2,5 @@ testpaths = tests/ morango/ DJANGO_SETTINGS_MODULE = testapp.settings norecursedirs = dist tmp* .svn .* +markers = + windows: mark a test as a windows test diff --git a/requirements/test.txt b/requirements/test.txt index aa53f8a2..ff49bc11 100644 --- a/requirements/test.txt +++ b/requirements/test.txt @@ -1,10 +1,10 @@ # These are for testing factory-boy==2.7.0 fake-factory==0.5.7 -coverage==4.5.1 +coverage==6.2 mock==2.0.0 -pytest==3.10.1 -pytest-cov==2.8.1 -pytest-django==3.8.0 +pytest==6.2.5 +pytest-cov==3.0.0 +pytest-django==4.5.2 more-itertools<=8.10.0 typing diff --git a/setup.py b/setup.py index d433fc9c..d867f6f8 100644 --- a/setup.py +++ b/setup.py @@ -45,6 +45,7 @@ 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', ], - python_requires=">=3.6, <3.12", + python_requires=">=3.6, <3.13", ) diff --git a/tests/patch_pytest.py b/tests/patch_pytest.py deleted file mode 100644 index 5033d224..00000000 --- a/tests/patch_pytest.py +++ /dev/null @@ -1,57 +0,0 @@ -""" -This script backports this Python 3.10 compatibility fix https://github.com/pytest-dev/pytest/pull/8540 -in order to allow pytest to run in Python 3.10 without upgrading to version 6.2.5 which does not support 2.7 -Copied from: -https://github.com/learningequality/kolibri/blob/8f9e78572d140a8e70e4d790903fe5acaf4f1a9a/test/patch_pytest.py -""" -import os -import subprocess -import sys - -import pytest - - -def patch(): - site_packages_dir = os.path.dirname(pytest.__file__) - - patch_file = os.path.join(os.path.dirname(__file__), "pytest_3.10.patch") - - print("Applying patch: " + str(patch_file)) - - # -N: insist this is FORWARD patch, don't reverse apply - # -p1: strip first path component - # -t: batch mode, don't ask questions - patch_command = [ - "patch", - "-N", - "-p1", - "-d", - site_packages_dir, - "-t", - "-i", - patch_file, - ] - print(" ".join(patch_command)) - try: - # Use a dry run to establish whether the patch is already applied. - # If we don't check this, the patch may be partially applied (which is bad!) - subprocess.check_output(patch_command + ["--dry-run"]) - except subprocess.CalledProcessError as e: - if e.returncode == 1: - # Return code 1 means not all hunks could be applied, this usually - # means the patch is already applied. - print( - "Warning: failed to apply patch (exit code 1), " - "assuming it is already applied: ", - str(patch_file), - ) - else: - raise e - else: - # The dry run worked, so do the real thing - subprocess.check_output(patch_command) - - -if __name__ == "__main__": - if sys.version_info >= (3, 10): - patch() diff --git a/tests/pytest_3.10.patch b/tests/pytest_3.10.patch deleted file mode 100644 index 4c933e99..00000000 --- a/tests/pytest_3.10.patch +++ /dev/null @@ -1,38 +0,0 @@ -diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py -index 4f96b9e8c..1aa5b12de 100644 ---- a/_pytest/assertion/rewrite.py -+++ b/_pytest/assertion/rewrite.py -@@ -587,10 +587,6 @@ class AssertionRewriter(ast.NodeVisitor): - return - # Insert some special imports at the top of the module but after any - # docstrings and __future__ imports. -- aliases = [ -- ast.alias(py.builtin.builtins.__name__, "@py_builtins"), -- ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), -- ] - doc = getattr(mod, "docstring", None) - expect_docstring = doc is None - if doc is not None and self.is_rewrite_disabled(doc): -@@ -617,6 +613,22 @@ class AssertionRewriter(ast.NodeVisitor): - pos += 1 - else: - lineno = item.lineno -+ # Now actually insert the special imports. -+ if sys.version_info >= (3, 10): -+ aliases = [ -+ ast.alias("builtins", "@py_builtins", lineno=lineno, col_offset=0), -+ ast.alias( -+ "_pytest.assertion.rewrite", -+ "@pytest_ar", -+ lineno=lineno, -+ col_offset=0, -+ ), -+ ] -+ else: -+ aliases = [ -+ ast.alias("builtins", "@py_builtins"), -+ ast.alias("_pytest.assertion.rewrite", "@pytest_ar"), -+ ] - imports = [ - ast.Import([alias], lineno=lineno, col_offset=0) for alias in aliases - ] diff --git a/tox.ini b/tox.ini index a5de8a7c..ec4d522d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - py{3.6,3.7,3.8,3.9,3.10,3.11}-cryptography{40.0.2} + py{3.6,3.7,3.8,3.9,3.10,3.11,3.12}-cryptography{40.0.2} postgres windows @@ -19,6 +19,7 @@ basepython = py3.9: python3.9 py3.10: python3.10 py3.11: python3.11 + py3.12: python3.12 postgres: python3.9 windows: python3.8 @@ -27,7 +28,6 @@ deps = cryptography40.0.2: cryptography==40.0.2 commands = sh -c '! tests/testapp/manage.py makemigrations --dry-run --exit --noinput' - python tests/patch_pytest.py python -O -m pytest {posargs:--cov=morango --color=no} [testenv:postgres] @@ -38,7 +38,6 @@ setenv = PYTHONPATH = {toxinidir}:{toxinidir}/tests/testapp DJANGO_SETTINGS_MODULE = testapp.postgres_settings commands = - python tests/patch_pytest.py python -O -m pytest {posargs:--cov=morango --color=no} [testenv:windows] @@ -47,5 +46,4 @@ deps = setenv = PYTHONPATH = {toxinidir}{:}{toxinidir}/tests/testapp commands = - python tests/patch_pytest.py python -O -m pytest {posargs:--cov=morango --color=no} -m windows