configuration support both:
- .env file
- settings.toml file
[default]
key = "value"
databases = { default = { url = "postgresql+psycopg://postgres:changeit@127.0.0.1:5432/workspace" } }
pg_url = "postgresql+psycopg://postgres:changeit@127.0.0.1:5432/workspace"
pg_a_url = "postgresql+psycopg_async://postgres:changeit@127.0.0.1:5432/workspace"
[test]
key = "abc"
databases.default.url = "postgresql+psycopg_async://postgres:changeit@127.0.0.1:5432/workspace"
def test_simple_kv():
assert settings.key == "value"
def test_nested_settings():
assert isinstance(settings.databases,dict)
- swith environment to test
- the database default url is changed to test environment, not default value anymore
def test_switch_env_variables():
qpyconf.ensure_env_settings(env_name="test")
assert qpyconf.settings.databases.default.url == "postgresql+psycopg_async://postgres:changeit@127.0.0.1:5432/workspace"
- env file
ENV_EXAMPLE='ENV_EXAMPLE'
- Get this value
def test_env_settings():
print(settings.env_example)
assert settings.env_example=="ENV_EXAMPLE"