-
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 rootdir should be where configured #12538
Comments
@slobinger, thanks for letting us know about this. We'll take a look at what we can do to make the pytest behavior more behavior when you have |
@luabud, this is consistently a point of confusion for users with less-common project structures. |
As requested, to bring a little more detail in, if configuration of a project is as follow: //....
"python.testing.pytestArgs": [
"-W ignore::DeprecationWarning:invoke.loader",
"-s",
"--rootdir=."
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.cwd": "app_src/test"
//... discover tests and run one of the founded tests via sidebar, I get the following Test Log:
python log:
@ericsnowcurrently just a little OT question. When you say "less-common project structures", which project structure would you suggest? |
Thanks. That helps. Note that the only thing the I expect part of the problem here is with the value you used for the |
I hope that didn't sound like a critique! 😄 It wasn't meant to. In the Python extension we expect (correctly, we believe) that most projects are relatively flat, such that the project root directory is the one that would go on
However, there's nothing wrong with the structure you have. It's just less common so we don't accommodate it as well in the extension. We'd like to improve that. Helping you with this issue actually helps that cause. 😄 |
Yes, that is, what I expact, too. And the reason I set the "python.testing.cwd" is that the configuration library we use (Dynaconf) requires that for our file structure. But sadly even if I omit In contrast I can run pytest from CLI without any problem. Maybe the fix for #6548 is not that good because it seems to force the rootdir to be the project path. meaning all relative test file paths musst be relative to project root. But that is not the case if one changes python.testing.cwd.
Oh no, I just was intrested - have seen so many different file structures for python projects. The one mentioned by you is definitly a very common one. We just desided for our project that it would makes our Dockerfile more complicated 😄 . |
I'm not sure that #6548 is exactly the same thing, though it is definitely at least closely related. Regardless, please provide the content of the "Python" and "Python test log" output panels. Both will offer some clues as to what's going on, like the exact command and CWD used to run pytest, and the pytest output text. Thanks! |
FWIW, I expect there is a bug in the extension that we'll need to fix. We just need to narrow down the problem. |
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. |
Sorry to resurrect an old issue, but I think I'm having the same problem. My project structure is not the most common one, but not so unusual either, I think.
However, when I try to discover the tests in vscode, I get this error:
It's trying to load From the output I found this command: 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. I tried setting Am I encountering the same problem as this issue or not? It's hard to tell. Any advice is appreciated. |
@hsharrison can you open a new issue to make this easier to track? |
Sure thing, thanks. Opened #14795 . |
Environment data
Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d
Date: 2020-06-17T21:13:08.304Z
Electron: 7.3.1
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 5.3.0-59-generic
python.languageServer
setting: "Microsoft"Expected behaviour
If I have the following directory structure:
And in the
.vscode/settings.json
the following config for pytest:I would expect the working directory is
app_src/test
relative to project root, same for pytestrootdir
.I also expect the the extra arg for
rootdir
is not needed because the described behavior in pytest for the rootdir is, that it is there the pytest.ini is found.With specified working directory I would expect that any tests found in test directory can manually be executed via sidebar.
Actual behaviour
But this is not the case. I get a file not found error:
Steps to reproduce:
create a project with the described structure and configuration and try to run single tests or testsfiles within sidbar.
suggestion
I would suggest that the pytest integration in vscode follows as exactly as possbile the behavior of pytest itself.
It should alway work to execute the discovered testfiles if absolute paths are used. For Test discovery it is a musst have to respect the
--rootdir
argument, so that the discovery does not fail because of errors in imports of no-test-modules.If
--rotdir
is not respected it musst be documented, that it is useless to set this argument.At the moment I have only to workarounds:
I prefer 1. 😄 .
The text was updated successfully, but these errors were encountered: