I'm reading env variables from .prod.env
file in my config.py:
from pydantic import BaseSettings
class Settings(BaseSettings):
A: int
class Config:
env_file = ".prod.env"
env_file_encoding = "utf-8"
settings = Settings()
in my main.py I'm creating the app
like so:
from fastapi import FastAPI
from app.config import settings
app = FastAPI()
print(settings.A)
I am able to override settings variables like this in my conftest.py
:
import pytest
from fastapi.testclient import TestClient
from app.main import app
from app.config import settings
settings.A = 42
@pytest.fixture(scope="module")
def test_clinet():
with TestClient(app) as client:
yield client
This works fine, whenever I use settings.A
I get 42.
But is it possible to override the whole env_file
from .prod.env
to another env file .test.env
?
Also I probably want to call settings.A = 42
in conftest.py before I import app
, right?