From 265ca58fbe9ec71ec3e7c80bc3ac2641b2fc8358 Mon Sep 17 00:00:00 2001 From: Thomas Moreau Date: Mon, 14 Mar 2022 20:05:15 +0100 Subject: [PATCH] FIX pytest configuration with fixture instead of conftest (#300) --- benchopt/cli/main.py | 16 ++++++++++------ benchopt/tests/{conftest.py => fixtures.py} | 0 conftest.py | 1 - pyproject.toml | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) rename benchopt/tests/{conftest.py => fixtures.py} (100%) delete mode 120000 conftest.py diff --git a/benchopt/cli/main.py b/benchopt/cli/main.py index 2823e1514..5c0204d3a 100644 --- a/benchopt/cli/main.py +++ b/benchopt/cli/main.py @@ -309,7 +309,14 @@ def install(benchmark, solver_names, dataset_names, force=False, 'a temporary one is created for the test.') @click.argument('pytest_args', nargs=-1, type=click.UNPROCESSED) def test(benchmark, env_name, pytest_args): - pytest_args = ' '.join(pytest_args) + + from benchopt.tests import __file__ as _bench_test_module + _bench_test_module = Path(_bench_test_module).parent + + pytest_args = ' '.join(( + "-p benchopt.tests.fixtures", f"--rootdir {_bench_test_module}", + *pytest_args + )) if len(pytest_args) == 0: pytest_args = '-vl' @@ -324,13 +331,10 @@ def test(benchmark, env_name, pytest_args): ) env_option = f'--test-env {env_name}' - from benchopt.tests import __file__ as _bench_test_module - BENCHMARK_TEST_FILE = ( - Path(_bench_test_module).parent / "test_benchmarks.py" - ) + _bench_test_file = _bench_test_module / "test_benchmarks.py" cmd = ( - f'pytest {pytest_args} {BENCHMARK_TEST_FILE} ' + f'pytest {pytest_args} {_bench_test_file} ' f'--benchmark {benchmark} {env_option} ' # Make sure to not modify sys.path to add test file from current env # in sub conda env as there might be different python versions. diff --git a/benchopt/tests/conftest.py b/benchopt/tests/fixtures.py similarity index 100% rename from benchopt/tests/conftest.py rename to benchopt/tests/fixtures.py diff --git a/conftest.py b/conftest.py deleted file mode 120000 index 8225fe41c..000000000 --- a/conftest.py +++ /dev/null @@ -1 +0,0 @@ -benchopt/tests/conftest.py \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index afb7cf5c2..34d4ecdfe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ local_scheme = "no-local-version" [tool.pytest.ini_options] minversion = "6.0" -addopts = "-v" +addopts = "-v -p benchopt.tests.fixtures" testpaths = [ "benchopt", ]