-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
pytest test discovery tries to import conftest.py from other projects #14795
Comments
Hi @hsharrison, thank you for extracting your issue out! A couple of things here:
Thank you 🙂 |
Thanks for taking a look. In the most recent version I have the problem Anyways, I created this repo: https://github.com/hsharrison/test-repo The repo doesn't include those other directories that it's finding, but cloning the above repo twice should replicate it. Here's my output after following the installation instructions in the repo and then (1) setting the python interpreter to
|
Thanks for helping me look into this...
Not that I can see.
That's right, I opened it from the project directory, not my home directory. I never open vscode in the parent directory where I would see both project
Maybe I don't follow this part, but it seems strange to me to run it from here. I always run it from the project root (also where I open vscode)
No luck doing these and trying again.
Nope. Seems like we're a bit stuck. I still think the root problem is |
Yeah, I just wanted to double-check, since I couldn't repro your issue when opening the workspace from the project root. You mentioned a variant of it above, but can you confirm that running It should return something like [
{
"rootid":".",
"root":"/Users/<user>/Documents/src/test-repo-one",
"parents":[
{
"id":"./tests",
"kind":"folder",
"name":"tests",
"parentid":".",
"relpath":"./tests"
},
{
"id":"./tests/test_packagename.py",
"kind":"file",
"name":"test_packagename.py",
"parentid":"./tests",
"relpath":"./tests/test_packagename.py"
}
],
"tests":[
{
"id":"./tests/test_packagename.py::test_add",
"name":"test_add",
"source":"./tests/test_packagename.py:4",
"markers":[
],
"parentid":"./tests/test_packagename.py"
}
]
}
] It might also be an issue with the |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on then we will be happy to re-open this issue to pick up where we left off. Thank you! |
Originally posted in #12538, I thought maybe it was the same problem, but I'm not sure.
My project structure is not the most common one, but not so unusual either, I think.
setup.cfg
contains thepytest
settings such that simple runningpytest
from<project-root>
works perfectly.However, when I try to discover the tests in vscode, I get this error:
It's trying to load
conftest.py
from two other projects!! I've confirmed that these projects are not installed in the conda env or accidentally cached anywhere (everywhere I could think to check). The project I'm working on has no reason to know that this project exists.From the output I found this command:
python /home/<user>/.local/share/code-server/extensions/ms-python.python-2020.5.86806/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir <project-path> -s
If I manually run this command in my project root, it works perfectly. If I run it from my home directory, I replicate the problem where it tries to load the wrong project. In fact, the two projects it's trying to load, are the only two that have a
conftest.py
anywhere within my home directory.I tried setting
python.testing.cwd
to<project-path>
but it didn't change anything. I can't think of anything else. In the end my best guess is thatrun_adapter.py
should be run from the project path rather than my home directory.Any advice is appreciated. I'm willing to believe its PEBCAK and not a bug, but either way I'd be grateful for a solution.
Originally posted by @hsharrison in #12538 (comment)
The text was updated successfully, but these errors were encountered: