fixtures.datafile module

fixtures.datafile.datafile(filename, replacements)[source]

datafile fixture, with templating support

Parameters:
  • filename – filename to load from the data dir
  • replacements – template replacements

Returns: Path to the loaded datafile

Usage:

Given a filename, it will attempt to open the given file from the
test's corresponding data dir. For example, this:

    datafile('testfile') # in tests/subdir/test_module_name.py

Would return a file object representing this file:

    /path/to/cfme_tests/data/subdir/test_module_name/testfile

Given a filename with a leading slash, it will attempt to load the file
relative to the root of the data dir. For example, this:

    datafile('/common/testfile') # in tests/subdir/test_module_name.py

Would return a file object representing this file:

    /path/to/cfme_tests/data/common/testfile

Note that the test module name is not used with the leading slash.

Templates:

This fixture can also handle template replacements. If the datafile being loaded is a python template, the dictionary of replacements can be passed as the ‘replacements’ keyword argument. In this case, the returned data file will be a NamedTemporaryFile prepopulated with the interpolated result from combining the template with the replacements mapping.

fixtures.datafile.pytest_addoption(parser)[source]
fixtures.datafile.pytest_sessionfinish(session, exitstatus)[source]