# Testing

Facilitate testing of code which uses staticconf.

class `staticconf.testing.``MockConfiguration`(*args, **kwargs)

  A context manager which replaces the configuration namespace while inside the context. When the context exits the old configuration values will be restored to that namespace.

      import staticconf.testing

      config = {
          ...
      }
      with staticconf.testing.MockConfiguration(config, namespace='special'):
          # Run your tests.
      ...

  Parameters:

  - namespace – the namespace to patch
  - flatten – if True the configuration will be flattened (default True)
  - args – passed directly to the constructor of `dict` and used as configuration data
  - kwargs – passed directly to the constructor of `dict` and used as configuration data

class `staticconf.testing.``PatchConfiguration`(*args, **kwargs)

  A context manager which updates the configuration namespace while inside the context. When the context exits the old configuration values will be restored to that namespace.

  Unlike MockConfiguration which completely replaces the configuration with the new one, this class instead only updates the keys in the configuration which are passed to it. It preserves all previous values that weren’t updated.

      import staticconf.testing

      config = {
          ...
      }
      with staticconf.testing.PatchConfiguration(config, namespace='special'):
          # Run your tests.
      ...

  The arguments are identical to MockConfiguration.