VSCode's python debugging and testing tool automatically loads .env
Question:
I have two .env files called .env
and .test.env
I’m loading my pydantic settings using the env_file = ".test.env"
like this:
from pydantic import BaseSettings
class Settings(BaseSettings):
A: int
class Config:
env_file = ".test.env"
env_file_encoding = "utf-8"
settings = Settings()
This works fine when I run the script from terminal like:
uvicorn run:app
But, when I use the VScode Debugging or Testing, it overrides env values set in .test.env with values from .env
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"run:app",
"--reload"
],
"justMyCode": true
}
]
}
How can I stop VScode from exporting the .env file?
Answers:
Found out there is a setting in vscode called Python: Env File
with path to env file. Removing the path solved the problem.
I have two .env files called .env
and .test.env
I’m loading my pydantic settings using the env_file = ".test.env"
like this:
from pydantic import BaseSettings
class Settings(BaseSettings):
A: int
class Config:
env_file = ".test.env"
env_file_encoding = "utf-8"
settings = Settings()
This works fine when I run the script from terminal like:
uvicorn run:app
But, when I use the VScode Debugging or Testing, it overrides env values set in .test.env with values from .env
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"run:app",
"--reload"
],
"justMyCode": true
}
]
}
How can I stop VScode from exporting the .env file?
Found out there is a setting in vscode called Python: Env File
with path to env file. Removing the path solved the problem.