-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
How to change the default rootdir ($PWD) to some other path #4594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Found a potential solution using In the top-level source directory, have
In the build directory, duplicate relevant options from the top-level
Adding Is this supported/recommended? It is not exactly documented at https://docs.pytest.org/en/latest/customize.html#rootdir Edit: one issue with this solution is that nodeids in |
Is |
Sometimes, but not always. I often have |
Does using |
It would not, the goal was to avoid adding explicit options while in the build directory. Adding So one remaing question, is it supported to have an explicit test directory in pytest.ini ( |
Why was this issue closed? |
Hi @nnop, Not sure why it was closed, @Zac-HD usually leaves the reason when closing an issue. Anyway,
This is supported by using More info: https://docs.pytest.org/en/latest/customize.html#finding-the-rootdir |
Thanks for the quick responding. @nicoddemus |
Let me try to quickly summarize:
Test files are always searched starting from paths given in the command-line. If if no path is given in the command-line, |
Great, now I'm clear on that. 😀 |
@nnop - we have a general policy of closing question-issues after two weeks of inactivity, which makes it easier for users and contributors to sort through all the other issues (e.g. bug reports and feature requests) we get. Glad @nicoddemus could help out though! |
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.ini
and$objdir/pytest.ini
containingtestpaths = test
andtestpaths = $srcdir/test
respectively. Unfortunately$srcdir/test/conftest.py
is initially not picked up andpytest_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?
The text was updated successfully, but these errors were encountered: