Is it possible to change the default rootdir (where tests and conftest.py are located) based on a file in the current working directory?
I am using pytest for testing a C project (not Python), so it is quite common to have a separate source and build directory. Additionally, tests are located in a subdirectory. The directory layout could be:
$srcdir/test/conftest.py (contains pytest_addoption and other stuff)
$srcdir/test/pytest.ini (contains python_files to override the test file pattern)
$srcdir/test/some_tests.py
Right now, tests are executed from the build (or source) directory by passing the test directory, e.g.:
srcdir$ pytest test
objdir$ pytest $srcdir/test
What I am trying to achieve is being able to run the same tests with:
srcdir$ pytest
objdir$ pytest
To this effect, I have tried to create $srcdir/pytest.ini and $objdir/pytest.ini containing testpaths = test and testpaths = $srcdir/test respectively. Unfortunately $srcdir/test/conftest.py is initially not picked up and pytest_addoption is not executed.
Essentially I want to redirect the rootdir by creating a file in the current working directory (source or build dir). Is this possible? What alternatives do I have, while trying to keep the number of pytest-related files (e.g. conftest.py) in the top-level directory to a minimum?
Is it possible to change the default rootdir (where tests and conftest.py are located) based on a file in the current working directory?
I am using pytest for testing a C project (not Python), so it is quite common to have a separate source and build directory. Additionally, tests are located in a subdirectory. The directory layout could be:
Right now, tests are executed from the build (or source) directory by passing the test directory, e.g.:
What I am trying to achieve is being able to run the same tests with:
To this effect, I have tried to create
$srcdir/pytest.iniand$objdir/pytest.inicontainingtestpaths = testandtestpaths = $srcdir/testrespectively. Unfortunately$srcdir/test/conftest.pyis initially not picked up andpytest_addoptionis not executed.Essentially I want to redirect the rootdir by creating a file in the current working directory (source or build dir). Is this possible? What alternatives do I have, while trying to keep the number of pytest-related files (e.g. conftest.py) in the top-level directory to a minimum?