-
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] If present, "python.testing.cwd" expected to change pytest --rootdir
arg value.
#9553
Comments
@chrisgervang, thanks for getting in touch with us. We'll take a look as soon as possible. |
Having looked this over, did you mean to file this as a bug or as a feature request? FWIW, I consider this a feature request. Just to be sure I understood, what you are asking for is that the "python.testing.cwd" setting be treated as the "root" directory against which the tests will be discovered/run. Is that correct? Assuming yes, I see three options:
If we do something about this then I expect it would be option 2. The reason is, "cwd" already has a specific meaning (essentially "the working directory of the executing program"). In the context of testing this often relates closely with the test root, which is part of the confusion here. (Sorry the help text for the setting, Oh, and what in particular connected the "python.testing.cwd" setting to pytest's |
Also, have you tried the multi-root workspace functionality of VS Code. You create a workspace and then "Add Folder to Workspace...". Consider adding each project root as a workspace root to see if that solves the problem for you. |
Gotcha, I agree with you that this is a feature request and #2 sounds like
a good addition given there is an existing, different semantic for CWD.
It was the quoted language in docs that led to my confusion - I thought
this was a bug and the expected behavior was to use CWD for —rootdir.
I haven’t tried the multiple workspace feature yet, but will give it a go.
Thanks for the suggestion. Looking at the plugin code, I’m not sure how
it’ll resolve multiple workspace folders down to one. Does it use the
“closest” (down the tree) folder of all the workspace folders added? I’ll
be interested to find out.
Thanks for looking into this!
…On Tue, Jan 14, 2020 at 11:16 AM Eric Snow ***@***.***> wrote:
Also, have you tried the multi-root workspace functionality of VS Code.
You create a workspace and then "Add Folder to Workspace...". Consider
adding each project root as a workspace root to see if that solves the
problem for you.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9553?email_source=notifications&email_token=AASY6273ODGS5PDTLSLV2OLQ5YFQFA5CNFSM4KFUZ4YKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEI5Y7FA#issuecomment-574328724>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASY62ZLCINBWJ6HGMBGRI3Q5YFQFANCNFSM4KFUZ4YA>
.
|
Sounds good. We'll make a decision on the request. As to multi-root workspace, the extension determines the current workspace based on the file in the active editor. Really it just calls the |
may be related: #7176 |
Thanks. I did work around this issue using the multi-root workspace functionality, and still interested in a decision. Feel free to close if the discussion has been moved. |
I just stumbled upon this. My So, 👍 for making the |
This also feels related to #8678. |
Any news on this? |
There is issue in our company we use old pytest v3 and giving --rootdir param is causing problems that we cannot use pytest discovery module. Please add option |
Any news on this? :) |
related to #12538 |
Couldn't this be fixed by removing This way if people wish to override the arg they can. |
Revisiting this, because it's still not clear to me how to configure my project. I've put up a minimal project with the same layout at https://github.com/bhrutledge/vscode-pytest-workspace. The latest commit gets it working with a hack, but the commit history shows my other attempts to get it working. @karthiknadig I think #17509 helped with test discovery by defaulting This is on the latest Insiders builds of VS Code and the Python extension. |
After some more digging, I think I've found two issues. First, during test discovery, it seems that vscode-python/src/client/testing/testController/pytest/arguments.ts Lines 137 to 141 in b6c0d3e
Second, during test running, vscode-python/src/client/testing/testController/pytest/runner.ts Lines 89 to 93 in b6c0d3e
However, this is different than test discovery, which uses vscode-python/src/client/testing/testController/pytest/pytestController.ts Lines 178 to 193 in b6c0d3e
It seems like this logic is already present in the vscode-python/src/client/testing/testController/pytest/pytestController.ts Lines 288 to 299 in b6c0d3e
|
Hello! I have just found and caught up on this issue and wanted to get feedback following the rewrite for our testing infrastructure. I do not think this feature request is fixed. The code now has @luabud and @karthiknadig, we do not have a precedence set for which one is used if both are provided do we? What would the risks with adopting something like this be in terms of potentially breaking other users by changing the order of precedence. |
Environment data
"python.jediEnabled"
set to; more info How to update the language server to the latest stable version #3977): Language ServerExpected behaviour
When running a test with a
settings.json
that contains the"python.testing.cwd": "root/dir"
option should result in a pytest command that uses"root/dir"
as the--rootdir
argument. If it isnull
, then fallback to existing behavior:--rootdir ${workspaceFolder}
.This is necessary for my use case since my code is in a monorepo and loads test fixtures from disk using paths relative to a project root rather than the repo root.
For example,
jfyi, I've anonymized
[~]
and[...testfolders]
.Actual behaviour
The
"python.testing.cwd"
setting has no visible effect on--rootdir
. It is always the "workspace folder", which makes sense given the code I linked to below.Relevant Code
vscode-python/src/client/testing/pytest/services/discoveryService.ts
Line 53 in 2b6a8f2
vscode-python/src/client/testing/pytest/main.ts
Lines 50 to 52 in 2b6a8f2
vscode-python/src/client/testing/pytest/main.ts
Lines 19 to 20 in 2b6a8f2
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
2a. configure "python.testing.cwd" in settings.json to the project root.
4a. Observe the test session starts and all tests pass that do not need to load fixtures from disk.
4b. Observe the output logs look like this:
Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)The text was updated successfully, but these errors were encountered: