-
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
Debugging pytest tests ignore the set .env file #12420
Comments
@flaker, thanks for letting us know about this. We'll take a look and get back to you as soon as possible. |
The You can also set (See: https://code.visualstudio.com/docs/python/testing#_debug-tests) Do you get the same problem if you add a debugger config with "envFile" set in it, like the following, in .vscode/launch.json: {
"name": "Debug Flask Tests",
"type": "python",
"request": "test",
"envFile": "/Users/myuser/dev/project/backend/.env.local_test"
} What about if you set "env" there? {
"name": "Debug Flask Tests",
"type": "python",
"request": "test",
"env": {
"PYTHONPATH": "../backend-lib:$PYTHONPATH",
"FLASK_APP": "api.app",
"FLASK_ENV": "development",
"DEBUG": true
}
} Using the explicit "env" will help to identify if the debugger is having trouble with the content of the .env file. Also, please refer to the docs on debugging flask apps, though that doesn't relate to running tests. |
Hello @ericsnowcurrently Suggestion 1: (from the path bar)
It did not work, showed the exact same error. The modification to PYTHONPATH inside
Suggestion 2:
failed with the exact same error. I've also tried using a full PYTHONPATH on that last solution. Thinking that the extension might be having issues with the relative path. Let me know if you want to try something else. |
Thanks, that helps. It looks like our handling of .env files isn't quite right in the testing case (but correct in the other debug cases). In fact, the code for the debug config used for testing is almost completely distinct from that used for other debug scenarios. The same goes, to a lesser extent, for other uses of .env files in the Python extension. From what I can tell, we don't do any substitution relative to the process environment variables. Regardless, we will investigate further and work on a fix. |
Leaving this comment in case someone is also bumping into this. So, I was trying to workaround this and thought "I can use a pth file". Added the file to the pipenv created venv site-packages ( Then I thought. Maybe it's pointing to the wrong |
Hello @flaker I concur. The issue exists and have been trying to wrap my head around trying various other tips and tricks. I tried additionally doing the following with no luck:
Additionally I check |
I'm having spent almost a day trying to figure out why my tests don't debug, only to just now find out it's a VS Code bug :|. |
For the moment what I did is just be sure my tests have the proper |
Hello! I have reviewed this issue and have tested a similar scenario successfully on our testing rewrite. Therefore I am going to close this issue but please comment or open a new issue if you are still seeing a problem when you try this yourself! To use the rewrite yourself just add Thanks! |
Environment data
"python.jediEnabled"
set to; more info How to update the language server to the latest stable version #3977): Lang serverpython.languageServer
setting: "Microsoft"Expected behaviour
Click on "Run Test" will execute the test.
Click on "Debut Test" will execute the test and stop in my breakpoint.
Actual behaviour
"Run Test" works as expected.
"Debug Test" starts the test execution but fails to load a library.
Steps to reproduce:
[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]
Create a python project with the following format:
Set:
The content of .env.local_test
It's important to notice that discovery and (non debug) run are behaving properly.
Logs
From Debug Console:
There is no output from under "Python" or "Python Test Logs"
The text was updated successfully, but these errors were encountered: