From c13dfad50672c919b498ee378c0d6064445f5a6b Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Fri, 30 Oct 2026 18:45:54 +0100 Subject: [PATCH] test: write the example benchmark inside the pytester sandbox tests/examples/test_addition_fixture.py was only input for pytester-based tests, but its name made pytest collect it as a test unless an ignore option kept it out. Those ignores were path-relative, so the wheel tests, which run from another directory, still collected it. Keep its source in an ADDITION_BENCHMARK constant that each test writes into its pytester sandbox with makepyfile, and drop the tests/examples ignores from the pytest config and the cibuildwheel test command. Closes COD-4080 Co-Authored-By: Claude Opus 5.5 --- pyproject.toml | 4 ++-- tests/conftest.py | 7 +++++++ tests/examples/__init__.py | 0 tests/examples/test_addition_fixture.py | 4 ---- tests/test_pytest_plugin.py | 9 +++++---- tests/test_pytest_plugin_cpu_instrumentation.py | 3 ++- tests/test_pytest_plugin_walltime.py | 4 ++-- 7 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 tests/examples/__init__.py delete mode 100644 tests/examples/test_addition_fixture.py diff --git a/pyproject.toml b/pyproject.toml index 4d114235..e772d147 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,7 +106,7 @@ push = false build = "cp*{manylinux,macosx}*" enable = ["cpython-prerelease"] test-extras = ["build", "test", "compat"] -test-command = "pytest -v --ignore={project}/tests/benchmarks --ignore={project}/tests/examples {project}/tests" +test-command = "pytest -v --ignore={project}/tests/benchmarks {project}/tests" [tool.cibuildwheel.linux] environment = { PYTEST_CODSPEED_FORCE_EXTENSION_BUILD = "1", PYTEST_CODSPEED_FORCE_VALGRIND_TESTS = "1" } @@ -136,7 +136,7 @@ force_grid_wrap = 0 float_to_top = true [tool.pytest.ini_options] -addopts = "--ignore=tests/benchmarks --ignore=tests/examples --ignore=tests/benchmarks/TheAlgorithms" +addopts = "--ignore=tests/benchmarks --ignore=tests/benchmarks/TheAlgorithms" filterwarnings = ["ignore::DeprecationWarning:pytest_benchmark.utils.*:"] pythonpath = ["tests/benchmarks/TheAlgorithms", "./scripts"] diff --git a/tests/conftest.py b/tests/conftest.py index c03d0748..04a81747 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -62,6 +62,13 @@ reason="pytest_xdist not installed", ) +ADDITION_BENCHMARK = """ +def test_some_addition_performance(benchmark): + @benchmark + def _(): + return 1 + 1 +""" + @pytest.fixture(scope="function") def codspeed_env(monkeypatch): diff --git a/tests/examples/__init__.py b/tests/examples/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/examples/test_addition_fixture.py b/tests/examples/test_addition_fixture.py deleted file mode 100644 index 6f73f821..00000000 --- a/tests/examples/test_addition_fixture.py +++ /dev/null @@ -1,4 +0,0 @@ -def test_some_addition_performance(benchmark): - @benchmark - def _(): - return 1 + 1 diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index a2666493..d0873727 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -1,5 +1,6 @@ import pytest from conftest import ( + ADDITION_BENCHMARK, IS_PERF_TRAMPOLINE_SUPPORTED, MeasurementMode, run_pytest_codspeed_with_mode, @@ -31,7 +32,7 @@ def fn(arg, kwarg=None): def test_bench_enabled_header_without_perf( pytester: pytest.Pytester, codspeed_env ) -> None: - pytester.copy_example("tests/examples/test_addition_fixture.py") + pytester.makepyfile(ADDITION_BENCHMARK) with codspeed_env(): result = pytester.runpytest() result.stdout.fnmatch_lines( @@ -41,7 +42,7 @@ def test_bench_enabled_header_without_perf( @skip_without_valgrind def test_plugin_enabled_by_env(pytester: pytest.Pytester, codspeed_env) -> None: - pytester.copy_example("tests/examples/test_addition_fixture.py") + pytester.makepyfile(ADDITION_BENCHMARK) with codspeed_env(): result = pytester.runpytest() result.stdout.fnmatch_lines(["*1 benchmarked*", "*1 passed*"]) @@ -49,7 +50,7 @@ def test_plugin_enabled_by_env(pytester: pytest.Pytester, codspeed_env) -> None: @skip_without_valgrind def test_plugin_enabled_and_env(pytester: pytest.Pytester, codspeed_env) -> None: - pytester.copy_example("tests/examples/test_addition_fixture.py") + pytester.makepyfile(ADDITION_BENCHMARK) with codspeed_env(): result = pytester.runpytest("--codspeed") result.stdout.fnmatch_lines(["*1 benchmarked*", "*1 passed*"]) @@ -122,7 +123,7 @@ def test_child(self): @xfail_pytest_benchmark_on_pytest_9_2 def test_plugin_disabled(pytester: pytest.Pytester) -> None: - pytester.copy_example("tests/examples/test_addition_fixture.py") + pytester.makepyfile(ADDITION_BENCHMARK) result = pytester.runpytest() result.stdout.fnmatch_lines(["*1 passed*"]) diff --git a/tests/test_pytest_plugin_cpu_instrumentation.py b/tests/test_pytest_plugin_cpu_instrumentation.py index 2e810b32..ce32fa50 100644 --- a/tests/test_pytest_plugin_cpu_instrumentation.py +++ b/tests/test_pytest_plugin_cpu_instrumentation.py @@ -2,6 +2,7 @@ import pytest from conftest import ( + ADDITION_BENCHMARK, run_pytest_codspeed_with_mode, skip_with_pytest_benchmark, skip_without_perf_trampoline, @@ -17,7 +18,7 @@ def test_bench_enabled_header_with_perf( pytester: pytest.Pytester, codspeed_env ) -> None: - pytester.copy_example("tests/examples/test_addition_fixture.py") + pytester.makepyfile(ADDITION_BENCHMARK) with codspeed_env(): result = pytester.runpytest() result.stdout.fnmatch_lines( diff --git a/tests/test_pytest_plugin_walltime.py b/tests/test_pytest_plugin_walltime.py index 0aaaa76e..a9008bd5 100644 --- a/tests/test_pytest_plugin_walltime.py +++ b/tests/test_pytest_plugin_walltime.py @@ -2,7 +2,7 @@ from typing import TYPE_CHECKING -from conftest import run_pytest_codspeed_with_mode +from conftest import ADDITION_BENCHMARK, run_pytest_codspeed_with_mode if TYPE_CHECKING: import pytest @@ -19,7 +19,7 @@ def test_bench_enabled_header_with_perf( pytester: pytest.Pytester, ) -> None: - pytester.copy_example("tests/examples/test_addition_fixture.py") + pytester.makepyfile(ADDITION_BENCHMARK) result = run_pytest_codspeed_with_mode(pytester, MeasurementMode.WallTime) result.stdout.fnmatch_lines(["*test_some_addition_performance*", "*1 benchmarked*"])