Modifications in the `.env` are not immediately applied
See original GitHub issueEnvironment data
- VS Code version: 1.33.1
- Extension version (available under the Extensions sidebar): 2019.4.1 (python extension)
- OS and version: Linux x64 4.15.0-48-generic snap
- Python version (& distribution if applicable, e.g. Anaconda): 3.6
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
Expected behaviour
Changes in the .env
file, its filename, the python.envFile
setting or the envFile
setting are immediately taken into account
Actual behaviour
Conditions: Unit tests with pytest
For example, in order for the setting python.envFile
to be taken into account (if added or updated), I had to relaunch VSCode or close the folder and reopening it. The same situation occurs when I motidy my .env
file.
sidenote: it is not clear whether to use envFile
or python.envFile
…
settings.json
{
"python.linting.pylintEnabled": false,
"python.linting.pep8Enabled": true,
"python.linting.enabled": true,
"python.linting.pep8Args": ["--max-line-length=120" ],
"python.pythonPath": "/home/<user>/miniconda2/envs/dspt/bin/python",
"python.testing.unittestEnabled": false,
"python.testing.pyTestEnabled": true,
"python.testing.nosetestsEnabled": false,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.envFile": "${workspaceFolder}/.env"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "test",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
.env file
TEST_VAR="foo"
Test case
import os
import pytest
def test_env():
a = os.environ.get("TEST_VAR")
assert a == 'foo'
```
Normally everything should be great and the test is PASS
Now,
* change the `TEST_VAR` to `bar` and the test is also be PASS
* another example, rename `.env` file to `test.env` and withou modifying the `settings.json` file, and the test is still be PASS
[example.zip](https://github.com/Microsoft/vscode-python/files/3132884/example.zip)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (1 by maintainers)
Top Results From Across the Web
5 reasons why your .env environment variables don't work
Most dev servers don't watch for changes in .env files. If you add or update them later, they won't be reflected in your...
Read more >Environment variable not updating with current value
Solved: Hi, Within an unmanaged solution I'm trying to update my environment variable from its default to its current value but it does...
Read more >javascript - .env file not updating in local environment in react js
Changing env variables requires to restart node server to take the new values. But sometimes , it doesn't work , so you mush...
Read more >How do you add a Windows environment variable without ...
Changes to environment variables should take effect immediately, ... I'm not able to tell from your problem description what specific ...
Read more >We need to talk about the .env | Platform.sh
env files are increasingly popular as a way to configure an application. ... you may not want to fiddle with environment variables directly....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gandroz Thanks for the hint about restarting VS Code to get this working. I have been beating my head against this for a little while and it’s good to have a workaround.
Maybe I can add another wrinkle to this story: when I run pytest in debug mode, it picks up the .env changes immediately. When running the tests normally (no debug) I needed to restart VS Code. I’m doing all of this through the test explorer with default launch.json configs.
workspace settings.json:
I believe this is actually a dupe of https://github.com/microsoft/vscode-python/issues/3805.