Testing
You can test your code using config_override
in your tests to test various
configuration values.
For example:
# testdebug.py
"""
Minimal example showing how to override configuration values when testing.
"""
import unittest
from everett.manager import ConfigManager, config_override
class App:
def __init__(self):
config = ConfigManager.basic_config()
self.debug = config("debug", default="False", parser=bool)
class TestDebug(unittest.TestCase):
def test_debug_on(self):
with config_override(DEBUG="on"):
app = App()
self.assertTrue(app.debug)
def test_debug_off(self):
with config_override(DEBUG="off"):
app = App()
self.assertFalse(app.debug)
if __name__ == "__main__":
unittest.main()
- everett.manager.config_override(**cfg)
Allow you to override config for writing tests.
This can be used as a class decorator:
@config_override(FOO="bar", BAZ="bat") class FooTestClass(object): ...
This can be used as a function decorator:
@config_override(FOO="bar") def test_foo(): ...
This can also be used as a context manager:
def test_foo(): with config_override(FOO="bar"): ...
- Parameters:
cfg (str) –
- Return type:
ConfigOverride