File: test_envvar_prefix.py

package info (click to toggle)
python-dynaconf 3.2.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,900 kB
  • sloc: python: 21,464; sh: 9; makefile: 4
file content (46 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import annotations

import os

import pytest

from dynaconf import LazySettings

TOML = """
[global]
var = "my value"

[false]
thisvar = "should not be set"
"""


def test_envvar_prefix_lazysettings(tmpdir):
    os.environ["DYNACONF_PREFIXED_VAR"] = "this is prefixed"
    tmpfile = tmpdir.mkdir("sub").join("test_no_envvar_prefix.toml")
    tmpfile.write(TOML)

    settings = LazySettings(
        environments=True,
        envvar_prefix=False,
        settings_file=str(tmpfile),
    )

    assert settings.VAR == "my value"
    assert settings.DYNACONF_PREFIXED_VAR == "this is prefixed"


def test_envvar_prefix_false_from_envvar(tmpdir):
    os.environ["DYNACONF_PREFIXED_VAR"] = "this is prefixed"
    os.environ["ENVVAR_PREFIX_FOR_DYNACONF"] = "false"
    tmpfile = tmpdir.mkdir("sub").join("test_no_envvar_prefix.toml")
    tmpfile.write(TOML)

    settings = LazySettings(environments=True, settings_file=str(tmpfile))

    assert settings.VAR == "my value"
    assert settings.DYNACONF_PREFIXED_VAR == "this is prefixed"

    with pytest.raises(AttributeError):
        assert settings.THISVAR == "should not be set"
    del os.environ["ENVVAR_PREFIX_FOR_DYNACONF"]