diff --git a/pyproject.toml b/pyproject.toml index 4d11423..e772d14 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 c03d074..04a8174 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 e69de29..0000000 diff --git a/tests/examples/test_addition_fixture.py b/tests/examples/test_addition_fixture.py deleted file mode 100644 index 6f73f82..0000000 --- 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 a266649..d087372 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 2e810b3..ce32fa5 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 0aaaa76..a9008bd 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*"])