def test_get_fresh(): assert settings.MUSTBEFRESH == "first" environ["DYNACONF_MUSTBEFRESH"] = "second" with pytest.raises(AssertionError): # fresh should now be second assert settings.exists("MUSTBEFRESH") assert settings.get_fresh("MUSTBEFRESH") == "first" assert settings.get_fresh("MUSTBEFRESH") == "second" environ["DYNACONF_THISMUSTEXIST"] = "@int 1" # must tnot exist yet (not loaded) assert settings.exists("THISMUSTEXIST") is False # must exist because fresh will call loaders assert settings.exists("THISMUSTEXIST", fresh=True) is True # loaders run only once assert settings.get("THISMUSTEXIST") == 1 environ["DYNACONF_THISMUSTEXIST"] = "@int 23" del environ["DYNACONF_THISMUSTEXIST"] # this should error because envvar got cleaned # but it is not, so cleaners should be fixed assert settings.get_fresh("THISMUSTEXIST") is None with pytest.raises(AttributeError): settings.THISMUSTEXIST with pytest.raises(KeyError): settings["THISMUSTEXIST"] environ["DYNACONF_THISMUSTEXIST"] = "@int 23" load(settings) assert settings.get("THISMUSTEXIST") == 23
def test_get_fresh(): assert settings.MUSTBEFRESH == 'first' os.environ['DYNACONF_MUSTBEFRESH'] = 'second' with pytest.raises(AssertionError): # fresh should now be second assert settings.exists('MUSTBEFRESH') assert settings.get_fresh('MUSTBEFRESH') == 'first' assert settings.get_fresh('MUSTBEFRESH') == 'second' os.environ['DYNACONF_THISMUSTEXIST'] = '@int 1' # must tnot exist yet (not loaded) assert settings.exists('THISMUSTEXIST') is False # must exist because fresh will call loaders assert settings.exists('THISMUSTEXIST', fresh=True) is True # loaders run only once assert settings.get('THISMUSTEXIST') == 1 os.environ['DYNACONF_THISMUSTEXIST'] = '@int 23' del os.environ['DYNACONF_THISMUSTEXIST'] # this should error because envvar got cleaned # but it is not, so cleaners should be fixed assert settings.get_fresh('THISMUSTEXIST') is None with pytest.raises(AttributeError): settings.THISMUSTEXIST with pytest.raises(KeyError): settings['THISMUSTEXIST'] os.environ['DYNACONF_THISMUSTEXIST'] = '@int 23' os.environ['BLARG_THISMUSTEXIST'] = '@int 99' # namespace switch is deleting the variable with settings.using_namespace('BLARG'): assert settings.get('THISMUSTEXIST') == 99 assert settings.get('THISMUSTEXIST') == 23