-
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
python.testing.cwd ignored when discovering or running tests #8678
Comments
Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can. |
Hi @pbotsman 👋 Thank you for reaching out and thoroughly filling out the issue template 👍 I can confirm that I could reproduce your issue in the latest release of the extension (2019.11.49689), and that it doesn't happen in the previous release (2019.10.44104). Seems like we don't take A possible workaround while waiting for a fix would be to move the content of {
"python.pythonPath": "/path/to/python",
"python.testing.pytestArgs": [
"./tests/py",
"-v",
"-s",
"--log-cli-level", "INFO",
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true
} |
Hi @kimadeline, Thanks for the workaround. This is exactly what I did 👍 |
FWIW, I just stumbled upon this, and would love to see a fix that changes the working directory to |
@bhrutledge Please upvote the original comment to help up prioritize it. Thanks! |
I am running into this problem too - I am working in a team where others are using different IDEs... within their environment, their tests load a file from the same directory as the code. Even with adding the directory to the execution path to |
Any progress or workarounds for this issue? Setting option |
This looks like a bug. It also seems to affect the
See how the bottom line prints a different value of cwd. |
That seems to be because the extension sets |
Disclaimer: I have about zero days experience with Typescript, and the vscode-python extension... however I think the issue might have stemmed from this commit: |
I had a similar problem and in my case the problem was this, basically pytest doesn't add the directory to the Also related to #10005 |
I can confirm that it affects |
@flyte sounds good, thank you so much! |
@ChildishGiant and just to make sure, you have the tests set up to use pytest and not unittest (i.e. if you could share your |
The only relevant settings are this:
In my project all my tests are under a unit_tests folder. It reads files relative to that folder but the command used in Test Log |
I have also noticed after setting
or
The unit test results (pass or fail) are no longer updated in the TEST explorer. |
As @danstreeter and I pointed out before, the issue is that this extension forces the The fix is to perhaps have this as the default, but allow users to override the argument in their settings. The problem was introduced here 9fe2a76 |
@karthiknadig great to see that you took over. |
Merged a fix for this just now to main. Fix is essentially what #8678 (comment) said. If there is
Try this out with this build https://github.com/microsoft/vscode-python/suites/3858667759/artifacts/95863817 if that doesn't work please provide repro steps. |
Works for me Had to restart VS Code in order tests to appear in the sidebar without being nested inside |
(Apologies if this is a rediculously silly question...) Can it be uninstalled once installed when this fix reaches launch? |
@danstreeter You can install this and uninstall to restore your VS Code to stable extension or any extension version. Here is how you would do it:
Note, you can also click on the 'Gear' icon next to the extension in the extensions tab to install a specific version using "Install Another version..." If you want to try this out is complete isolation, you could install VS Code Insiders (which can install side by side with your stable one) and install this vsix there and test it out. then uninstall the whole thing. This way it won't touch your day-to-day VS Code instance. |
Thanks @karthiknadig , I've got it installed in my main 'day-to-day' instance however still not quite working for me... Using the default provided config after 'configuring tests', I end up with the following in my settings file: "python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"tests"
], This matches my project layout, as all tests are stored in the Running my tests with my normal workflow still works fine by running export PYTHONPATH=./src
pipenv run python -m pytest tests When performing discovery with the above config, I get the following in the Python output: ~/path-to-code/.venv/bin/python3.8 ~/.vscode/extensions/ms-python.python-2021.10.1267871984-dev/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir -s --cache-clear tests
Error 2021-09-24 19:51:20: Error discovering pytest tests:
[r [Error]: ============================= test session starts ==============================
platform darwin -- Python 3.8.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /
plugins: asyncio-0.15.1, html-3.1.1, metadata-1.11.0
collected 0 items I also get the following warning: PytestCacheWarning: could not create cache path /.pytest_cache/v/cache/stepwise Also, if I add any "python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--rootdir",
"my-root-dir-fake-name",
"tests"
], The error change as 'expected' with the root directory and trys to target a path on root: ~/path-to-code/.venv/bin/python3.8 ~/.vscode/extensions/ms-python.python-2021.10.1267871984-dev/pythonFiles/testing_tools/run_adapter.py discover pytest -- -s --cache-clear --rootdir my-root-dir-fake-name my-root-dir-fake-name
Error 2021-09-24 19:53:03: Error discovering pytest tests:
[r [Error]: ERROR: Directory '/my-root-dir-fake-name' not found. Check your '--rootdir' option. Why is it trying to target root? |
OOH OOH OOH - I FIXED IT!!! I needed an absolute path in the rootdir... Using my pseudo, sanitised example above - this now works! "python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--rootdir",
"/full/path/to/my/path-to-code",
"tests"
], --- Update --- This is much nicer: "python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--rootdir",
"${workspaceFolder}",
"tests"
], |
@danstreeter can you try:
|
Doing the above gives: > ~/path-to-code/.venv/bin/python3.8 ~/.vscode/extensions/ms-python.python-2021.10.1267871984-dev/pythonFiles/testing_tools/run_adapter.py discover pytest -- -s --cache-clear --rootdir ./tests ./tests
Error 2021-09-24 20:00:44: Error discovering pytest tests:
[r [Error]: ERROR: Directory '/tests' not found. Check your '--rootdir' option. |
@danstreeter Are you missing the '.' before the './tests'? Just checking because '/tests' will not work. |
The config in the last part of my previous post up a bit (#8678 (comment)) works perfect though. |
I see. Thanks for the input. This should work for most case with this:
I will tweak it, it seems like for some reason, the |
Environment data
"python.jediEnabled"
set to; more info How to update the language server to the latest stable version #3977): JediExpected behaviour
Tests are displayed in the test explorer according to
python.testing.cwd
setting and I am able to run single test or tests from single fileActual behaviour
python.testing.cwd
is ignored for displaying tests and I am unable to run single test or tests from single file because I am getting an errorfile not found
.Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
Sample project: https://github.com/pbotsman/sample_project
test_something
or tests insome_test.py
file.(Sometimes in order to reproduce the problem I had to relaunch my VSCode)
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
)Additional info
Looks like something has changed in the last release:
some_test.py
would be root test. I mean thattests/py
would be omitted in the test explorer since I have"python.testing.cwd": "tests/py"
in my settings.Currently directories
tests/py
are displayed in the test explorer even though I have this setting.file not found
. It looks like something is wrong with the file paths.When the command
~/.virtualenvs/sample_project/bin/python -m pytest --rootdir ~/projects/sample_project --junitxml=/var/folders/0_/6w94lk1171vc_fpwbjqx02nw0000gn/T/tmp-5598WI4lpp4kFEsC.xml -v -s --log-cli-level INFO ./tests/py/some_test.py::test_something
is called my current working directory is set to
python.testing.cwd
and that is why I am getting the error.So in the command mentioned above valid file path should be
./some_test.py::test_something
, not./tests/py/some_test.py::test_something
.The text was updated successfully, but these errors were encountered: