From b978059d48815ede38a628451efbe62f86325dd2 Mon Sep 17 00:00:00 2001 From: Logan Page Date: Mon, 4 Mar 2024 19:28:12 +0200 Subject: [PATCH 1/8] chore: add bumpversion, isort to dev requirements --- .bumpversion.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 969e33e..c99e6f9 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.2.2.dev0 +current_version = 0.2.2 parse = (?P\d+)\.(?P\d+)\.(?P\d+) (?:\.(?Pdev)(?P\d+))? From af80ce0545dafb692f6bcf94770e91d4c3192ee2 Mon Sep 17 00:00:00 2001 From: Logan Page Date: Mon, 4 Mar 2024 19:28:23 +0200 Subject: [PATCH 2/8] chore: bump version to 0.2.2 --- requirements-dev.txt | 2 ++ setup.py | 2 +- tests/example-project/setup.py | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index c45da54..a77fd65 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,7 @@ +bumpversion check-manifest cython flake8 +isort nox pytest diff --git a/setup.py b/setup.py index 7311422..74993f7 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ setup( name='pytest-cython', - version='0.2.2.dev0', + version='0.2.2', description='A plugin for testing Cython extension modules', long_description=long_description, long_description_content_type='text/markdown', diff --git a/tests/example-project/setup.py b/tests/example-project/setup.py index 0531960..d781261 100644 --- a/tests/example-project/setup.py +++ b/tests/example-project/setup.py @@ -38,7 +38,7 @@ setup( name='pytest-cython', - version='0.2.2.dev0', + version='0.2.2', description="Example Cython project for pytest-cython tests", package_dir={'': 'src'}, packages=['pypackage'], From ad9ef30a8b86afb5f2851c417ff355d2e8812098 Mon Sep 17 00:00:00 2001 From: Logan Page Date: Tue, 5 Mar 2024 09:16:44 +0200 Subject: [PATCH 3/8] chore: pin pytest>=4.6,<8 --- README.md | 9 +++++++++ setup.py | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef54e9f..1b04dab 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,15 @@ pytest --doctest-cython path/to/module.pyx It is assumed that the C extension modules have been build in place before running `py.test` and there is a matching Cython `.pyx` file +## Compatibility + +The following table describes the versions of Pytest and Cython the each version of the pytest-cython plugin is +compatible with. + +| Version | Pytest | Cython | +| ------- | ------ | ------- | +| 0.2.x | 6, 7 | 0.29, 3 | + ## Issues If you encounter any problems, please [file an issue](https://github.com/lgpage/pytest-cython/issues) along with a diff --git a/setup.py b/setup.py index 74993f7..f3ed24c 100755 --- a/setup.py +++ b/setup.py @@ -33,8 +33,6 @@ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', - 'Operating System :: Unix', - 'Operating System :: POSIX', 'Programming Language :: Python', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: Implementation :: CPython', @@ -46,7 +44,7 @@ 'pytest', 'py.test', 'cython', 'doctest', ], install_requires=[ - 'pytest>=4.6.0', + 'pytest>=4.6,<8', ], entry_points={ 'pytest11': [ From 53f1b3e3f8f3a5690d1e8b729c1fcdeb5b2fae09 Mon Sep 17 00:00:00 2001 From: Logan Page Date: Tue, 5 Mar 2024 09:18:27 +0200 Subject: [PATCH 4/8] chore: update test matrix * python: 3.10, 3.11, 3.12 * cython: 0.29, 3 * pytest: 6, 7 --- .github/workflows/python-test.yml | 11 +++-------- noxfile.py | 15 +++++---------- tests/example-project/setup.py | 23 ++++------------------- 3 files changed, 12 insertions(+), 37 deletions(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 9c43813..4b1f6ca 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -17,14 +17,9 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11", "pypy-3.9"] - pytest-version: ["5", "6", "7"] - cython-version: ["0.29"] - exclude: - - python-version: "3.10" - pytest-version: "5" - - python-version: "3.11" - pytest-version: "5" + python-version: ["3.10", "3.11", "3.12", "pypy"] + pytest-version: ["6", "7"] + cython-version: ["0.29", "3"] steps: - uses: actions/checkout@v4 diff --git a/noxfile.py b/noxfile.py index 557cccc..cb8e4a2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,17 +20,12 @@ def check(session): @nox.session -@nox.parametrize( - "python,pytest", - [ - (python, pytest) - for python in ("3.9", "3.10", "3.11", "pypy3") - for pytest in ("5", "6", "7") - if (python, pytest) != ("3.10", "5") and (python, pytest) != ("3.11", "5") - ], -) -@nox.parametrize('cython', ["0.29"]) +@nox.parametrize('python', ["3.10", "3.11", "3.12"]) +@nox.parametrize('pytest', ["6", "7"]) +@nox.parametrize('cython', ["0.29", "3"]) def test(session, pytest, cython): + session.install("--upgrade", "setuptools") + session.install(f"pytest=={pytest}.*") session.install(f"cython=={cython}.*") session.install("-e", ".") diff --git a/tests/example-project/setup.py b/tests/example-project/setup.py index d781261..5071a96 100644 --- a/tests/example-project/setup.py +++ b/tests/example-project/setup.py @@ -3,7 +3,6 @@ if __name__ == "__main__": - import os import sys from setuptools import setup @@ -11,29 +10,15 @@ from Cython.Build import cythonize directives = { - 'profile': True, + 'autotestdict': True, 'embedsignature': False, - 'linetrace': False, 'language_level': sys.version_info[0], - # this is the default, but use it explicitly in case that ever - # changes - 'autotestdict': True + 'linetrace': False, + 'profile': False, } - # Enable code coverage for C code: we can't use CFLAGS=-coverage in - # tox.ini, since that may mess with compiling dependencies (e.g. numpy). - # Therefore we set SETUPPY_CFLAGS=-coverage in tox.ini and copy it to - # CFLAGS here (after deps have been safely installed). - macros = [] - if 'TOXENV' in os.environ and 'SETUPPY_CFLAGS' in os.environ: - os.environ['CFLAGS'] = os.environ['SETUPPY_CFLAGS'] - if '-coverage' in os.environ['SETUPPY_CFLAGS']: - directives['linetrace'] = True - macros = [[('CYTHON_TRACE', '1'), ('CYTHON_TRACE_NOGIL', '1')]] - - extensions = [ - Extension('*', ['src/pypackage/*.pyx'], define_macros=macros) + Extension('*', ['src/pypackage/*.pyx']) ] setup( From 8f5df548446097f374e150e916c63706c1a5cc11 Mon Sep 17 00:00:00 2001 From: Logan Page Date: Tue, 5 Mar 2024 09:18:57 +0200 Subject: [PATCH 5/8] chore: clean the test project before each test --- tests/test_pytest_cython.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/tests/test_pytest_cython.py b/tests/test_pytest_cython.py index 3d64ebf..da98690 100644 --- a/tests/test_pytest_cython.py +++ b/tests/test_pytest_cython.py @@ -1,14 +1,17 @@ from __future__ import absolute_import -import py +import pathlib import pytest +import shutil + from setuptools.sandbox import run_setup import pytest_cython.plugin -PATH = py.path.local(__file__).dirpath() -PATH = PATH.join('example-project', 'src', 'pypackage') +ROOT_PATH = pathlib.Path(__file__).parent +PROJECT_PATH = ROOT_PATH.joinpath('example-project') +PACKAGE_PATH = PROJECT_PATH.joinpath('src', 'pypackage') PYTEST_MAJOR_VERSION = int(pytest.__version__.split('.')[0]) IMPORT_MODES = ['prepend', 'append'] @@ -17,7 +20,7 @@ def get_module(basename, suffix='.pyx'): - return PATH.join(basename + suffix) + return PACKAGE_PATH.joinpath(basename + suffix) def run_pytest(testdir, module, import_mode): @@ -26,15 +29,24 @@ def run_pytest(testdir, module, import_mode): @pytest.fixture(scope='module', autouse=True) def build_example_project(): - path = py.path.local(__file__).dirpath() - setup_py = path.join('example-project', 'setup.py') + shutil.rmtree(PROJECT_PATH.joinpath('build'), True) + shutil.rmtree(PACKAGE_PATH.joinpath('__pycache__'), True) + + for file in PACKAGE_PATH.glob('*.pyd'): + file.unlink() + + for file in PACKAGE_PATH.glob('*.c'): + file.unlink() + + setup_py = PROJECT_PATH.joinpath('setup.py') run_setup(str(setup_py), ['build_ext', '--inplace']) @pytest.mark.parametrize('import_mode', IMPORT_MODES) def test_cython_ext_module(testdir, import_mode): module = get_module('cython_ext_module') - assert module.check() + assert module.exists() + result = run_pytest(testdir, module, import_mode) result.stdout.fnmatch_lines([ "*Eggs.__init__ *PASSED*", @@ -58,7 +70,8 @@ def test_cython_ext_module(testdir, import_mode): @pytest.mark.parametrize('import_mode', IMPORT_MODES) def test_wrap_c_ext_module(testdir, import_mode): module = get_module('wrap_c_ext_module') - assert module.check() + assert module.exists() + result = run_pytest(testdir, module, import_mode) result.stdout.fnmatch_lines([ "*sqr*PASSED*", @@ -69,7 +82,8 @@ def test_wrap_c_ext_module(testdir, import_mode): @pytest.mark.parametrize('import_mode', IMPORT_MODES) def test_wrap_cpp_ext_module(testdir, import_mode): module = get_module('wrap_cpp_ext_module') - assert module.check() + assert module.exists() + result = run_pytest(testdir, module, import_mode) result.stdout.fnmatch_lines([ "*sqr*PASSED*", @@ -80,7 +94,8 @@ def test_wrap_cpp_ext_module(testdir, import_mode): @pytest.mark.parametrize('import_mode', IMPORT_MODES) def test_pure_py_module(testdir, import_mode): module = get_module('pure_py_module', suffix='.py') - assert module.check() + assert module.exists() + result = run_pytest(testdir, module, import_mode) result.stdout.fnmatch_lines([ "*Eggs.__init__*PASSED*", From 208fc8b3c7066a2dd1d946c9617779cad8d4ab01 Mon Sep 17 00:00:00 2001 From: Logan Page Date: Sat, 9 Mar 2024 11:19:05 +0200 Subject: [PATCH 6/8] chore: specify pypy version --- .github/workflows/python-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 4b1f6ca..8d4b6dd 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -17,7 +17,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest, windows-latest] - python-version: ["3.10", "3.11", "3.12", "pypy"] + python-version: ["3.10", "3.11", "3.12", "pypy3.10"] pytest-version: ["6", "7"] cython-version: ["0.29", "3"] From ff65e820aa9fa739956fb75d39c4d2132111db5c Mon Sep 17 00:00:00 2001 From: Logan Page Date: Sat, 9 Mar 2024 11:44:21 +0200 Subject: [PATCH 7/8] fix: install or upgrade setuptools --- .github/workflows/python-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 8d4b6dd..57cc660 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -32,6 +32,8 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + python -m pip install --upgrade setuptools + python -m pip install pytest==${{ matrix.pytest-version }}.* python -m pip install cython==${{ matrix.cython-version }}.* python -m pip install -e . From 96e3b0194c540ba6c7bfcfb226863e68a25a4115 Mon Sep 17 00:00:00 2001 From: Logan Page Date: Sat, 9 Mar 2024 11:47:24 +0200 Subject: [PATCH 8/8] fix: sort collected tests by test name --- src/pytest_cython/plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_cython/plugin.py b/src/pytest_cython/plugin.py index 28be1ba..62e0bfd 100644 --- a/src/pytest_cython/plugin.py +++ b/src/pytest_cython/plugin.py @@ -195,7 +195,7 @@ def collect(self): del tests[test_name] tests[equiv_test_name].lineno = lineno - for test in tests.values(): + for test in sorted(tests.values(), key=lambda x: x.name): if test.examples: # skip empty doctests if hasattr(DoctestItem, 'from_parent'): yield DoctestItem.from_parent(self, name=test.name, runner=runner, dtest=test)