The oslotest.createfile Module

class oslotest.createfile.CreateFileWithContent(filename, contents, ext='.conf', encoding='utf-8')

Bases: fixtures.fixture.Fixture

Create a temporary file with the given content.

Creates a file using a predictable name, to be used by tests for code that need a filename to load data or otherwise interact with the real filesystem.

Warning

It is the responsibility of the caller to ensure that the file is removed.

Users of this fixture may also want to use fixtures.NestedTempfile to set the temporary directory somewhere safe and to ensure the files are cleaned up.

path

The canonical name of the file created.

Parameters
  • filename – Base file name or full literal path to the file to be created.

  • contents – The data to write to the file. Unicode data will be encoded before being written.

  • ext – An extension to add to filename.

  • encoding – An encoding to use for unicode data (ignored for byte strings).

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.