Test Fixture

Test Fixture

class oslo_config.fixture.Config(conf=<oslo_config.cfg.ConfigOpts object>)

Allows overriding configuration settings for the test.

conf will be reset on cleanup.

config(**kw)

Override configuration values.

The keyword arguments are the names of configuration options to override and their values.

If a group argument is supplied, the overrides are applied to the specified configuration option group, otherwise the overrides are applied to the default group.

load_raw_values(group=None, **kwargs)

Load raw values into the configuration without registering them.

This method adds a series of parameters into the current config instance, as if they had been loaded by a ConfigParser. This method does not require that you register the configuration options first, however the values loaded will not be accessible until you do.

register_cli_opt(opt, group=None)

Register a single CLI option for the test run.

Options registered in this manner will automatically be unregistered during cleanup.

If a group argument is supplied, it will register the new option to that group, otherwise the option is registered to the default group.

CLI options must be registered before the command line and config files are parsed. This is to ensure that all CLI options are shown in –help and option validation works as expected.

register_cli_opts(opts, group=None)

Register multiple CLI options for the test run.

This works in the same manner as register_opt() but takes a list of options as the first argument. All arguments will be registered to the same group if the group argument is supplied, otherwise all options will be registered to the default group.

CLI options must be registered before the command line and config files are parsed. This is to ensure that all CLI options are shown in –help and option validation works as expected.

register_opt(opt, group=None)

Register a single option for the test run.

Options registered in this manner will automatically be unregistered during cleanup.

If a group argument is supplied, it will register the new option to that group, otherwise the option is registered to the default group.

register_opts(opts, group=None)

Register multiple options for the test run.

This works in the same manner as register_opt() but takes a list of options as the first argument. All arguments will be registered to the same group if the group argument is supplied, otherwise all options will be registered to the default group.

setUp()

Prepare the Fixture for use.

This should not be overridden. Concrete fixtures should implement _setUp. Overriding of setUp is still supported, just not recommended.

After setUp has completed, the fixture will have one or more attributes which can be used (these depend totally on the concrete subclass).

Raises

MultipleExceptions if _setUp fails. The last exception captured within the MultipleExceptions will be a SetupError exception.

Returns

None.

Changed in 1.3

The recommendation to override setUp has been reversed - before 1.3, setUp() should be overridden, now it should not be.

Changed in 1.3.1

BaseException is now caught, and only subclasses of Exception are wrapped in MultipleExceptions.

set_config_dirs(config_dirs)

Specify a list of config dirs to read.

This method allows you to predefine the list of configuration dirs that are loaded by oslo_config. It will ensure that your tests do not attempt to autodetect, and accidentally pick up config files from locally installed services.

set_config_files(config_files)

Specify a list of config files to read.

This method allows you to predefine the list of configuration files that are loaded by oslo_config. It will ensure that your tests do not attempt to autodetect, and accidentally pick up config files from locally installed services.

set_default(name, default, group=None)

Set a default value for an option.

This method is not necessarily meant to be invoked directly. It is here to allow the set_defaults() functions in various Oslo libraries to work with a Config fixture instead of a ConfigOpts instance.

Use it like:

class MyTest(testtools.TestCase):

    def setUp(self):
        super(MyTest, self).setUp()
        self.conf = self.useFixture(fixture.Config())

    def test_something(self):
        some_library.set_defaults(self.conf, name='value')
        some_library.do_something_exciting()
Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.