Skip to content

Commit

Permalink
Python 3.11 compatibility
Browse files Browse the repository at this point in the history
This patch adds the new arguments to the types.CodeType class
constructor in the clonefunc function.

This commit addresses ionelmc#231.

Co-authored-by:	Enji Cooper <[email protected]>
  • Loading branch information
danigm authored and ngie-eign committed Mar 12, 2023
1 parent 7ef2645 commit 826475c
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 1 deletion.
144 changes: 144 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,150 @@ jobs:
python_arch: 'x64'
tox_env: 'py310-pytest72-xdist-nocov'
os: 'macos-latest'
- name: 'py311-pytest71-nodist-cover (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-nodist-cover,codecov'
os: 'ubuntu-latest'
- name: 'py311-pytest71-nodist-cover (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-nodist-cover,codecov'
os: 'windows-latest'
- name: 'py311-pytest71-nodist-cover (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-nodist-cover,codecov'
os: 'macos-latest'
- name: 'py311-pytest71-nodist-nocov (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-nodist-nocov'
os: 'ubuntu-latest'
- name: 'py311-pytest71-nodist-nocov (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-nodist-nocov'
os: 'windows-latest'
- name: 'py311-pytest71-nodist-nocov (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-nodist-nocov'
os: 'macos-latest'
- name: 'py311-pytest71-xdist-cover (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-xdist-cover,codecov'
os: 'ubuntu-latest'
- name: 'py311-pytest71-xdist-cover (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-xdist-cover,codecov'
os: 'windows-latest'
- name: 'py311-pytest71-xdist-cover (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-xdist-cover,codecov'
os: 'macos-latest'
- name: 'py311-pytest71-xdist-nocov (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-xdist-nocov'
os: 'ubuntu-latest'
- name: 'py311-pytest71-xdist-nocov (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-xdist-nocov'
os: 'windows-latest'
- name: 'py311-pytest71-xdist-nocov (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest71-xdist-nocov'
os: 'macos-latest'
- name: 'py311-pytest72-nodist-cover (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-nodist-cover,codecov'
os: 'ubuntu-latest'
- name: 'py311-pytest72-nodist-cover (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-nodist-cover,codecov'
os: 'windows-latest'
- name: 'py311-pytest72-nodist-cover (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-nodist-cover,codecov'
os: 'macos-latest'
- name: 'py311-pytest72-nodist-nocov (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-nodist-nocov'
os: 'ubuntu-latest'
- name: 'py311-pytest72-nodist-nocov (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-nodist-nocov'
os: 'windows-latest'
- name: 'py311-pytest72-nodist-nocov (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-nodist-nocov'
os: 'macos-latest'
- name: 'py311-pytest72-xdist-cover (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-xdist-cover,codecov'
os: 'ubuntu-latest'
- name: 'py311-pytest72-xdist-cover (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-xdist-cover,codecov'
os: 'windows-latest'
- name: 'py311-pytest72-xdist-cover (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-xdist-cover,codecov'
os: 'macos-latest'
- name: 'py311-pytest72-xdist-nocov (ubuntu)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-xdist-nocov'
os: 'ubuntu-latest'
- name: 'py311-pytest72-xdist-nocov (windows)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-xdist-nocov'
os: 'windows-latest'
- name: 'py311-pytest72-xdist-nocov (macos)'
python: '3.11'
toxpython: 'python3.11'
python_arch: 'x64'
tox_env: 'py311-pytest72-xdist-nocov'
os: 'macos-latest'
- name: 'pypy37-pytest71-nodist-cover (ubuntu)'
python: 'pypy-3.7'
toxpython: 'pypy3.7'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Unreleased
----------

* Added Python 3.11 support.

4.0.0 (2022-10-26)
------------------

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def read(*names, **kwargs):
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Testing',
Expand Down
1 change: 1 addition & 0 deletions src/pytest_benchmark/compat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys

PY38 = sys.version_info[0] == 3 and sys.version_info[1] >= 8
PY311 = sys.version_info[0] == 3 and sys.version_info[1] >= 11
5 changes: 5 additions & 0 deletions src/pytest_benchmark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import genericpath

from .compat import PY38
from .compat import PY311

# This is here (in the utils module) because it might be used by
# various other modules.
Expand Down Expand Up @@ -521,6 +522,10 @@ def clonefunc(f):
co.co_firstlineno, co.co_lnotab, co.co_freevars, co.co_cellvars]
if PY38:
args.insert(1, co.co_posonlyargcount)

if PY311:
args.insert(12, co.co_qualname)
args.insert(15, co.co_exceptiontable)
co2 = types.CodeType(*args)
#
# then, we clone the function itself, using the new co2
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ envlist =
clean,
check,
docs,
{py37,py38,py39,py310,pypy37,pypy38,pypy39}-{pytest71,pytest72}-{nodist,xdist}-{cover,nocov},
{py37,py38,py39,py310,py311,pypy37,pypy38,pypy39}-{pytest71,pytest72}-{nodist,xdist}-{cover,nocov},
report
ignore_basepython_conflict = true

Expand All @@ -27,6 +27,7 @@ basepython =
py38: {env:TOXPYTHON:python3.8}
py39: {env:TOXPYTHON:python3.9}
py310: {env:TOXPYTHON:python3.10}
py311: {env:TOXPYTHON:python3.11}
{bootstrap,clean,check,report,docs,codecov,coveralls}: {env:TOXPYTHON:python3}
setenv =
PYTHONPATH={toxinidir}/tests
Expand Down

0 comments on commit 826475c

Please sign in to comment.