The oslotest.base Module¶
Common utilities used in testing
-
class
oslotest.base.BaseTestCase(*args, **kwds)¶ Bases:
testtools.testcase.TestCaseBase class for unit test classes.
If the environment variable
OS_TEST_TIMEOUTis set to an integer value, a timer is configured to control how long individual test cases can run. This lets tests fail for taking too long, and prevents deadlocks from completely hanging test runs.If the environment variable
OS_STDOUT_CAPTUREis set, a fake stream replacessys.stdoutso the test can look at the output it produces.If the environment variable
OS_STDERR_CAPTUREis set, a fake stream replacessys.stderrso the test can look at the output it produces.If the environment variable
OS_DEBUGis set to a true value, debug logging is enabled. Alternatively, theOS_DEBUGenvironment variable can be set to a valid log level.If the environment variable
OS_LOG_CAPTUREis set to a true value, a logging fixture is installed to capture the log output.Uses the fixtures module to configure a
NestedTempFileto ensure that all temporary files are created in an isolated location.Uses the fixtures module to configure a
TempHomeDirto change theHOMEenvironment variable to point to a temporary location.PLEASE NOTE: Usage of this class may change the log level globally by setting the environment variable
OS_DEBUG. A mock oftime.timewill be called many more times than might be expected because it’s called often by the logging module. A usage of such a mock should be avoided when a test needs to verify logging behavior or counts the number of invocations. A workaround is to overload the_fake_logsfunction in a base class but this will deactivate fake logging globally.-
addCleanup(function, *args, **kwargs)¶
-
create_tempfiles(files, ext='.conf', default_encoding='utf-8')¶ Safely create temporary files.
Parameters: - files (list of tuple) – Sequence of tuples containing (filename, file_contents).
- ext (str) – File name extension for the temporary file.
- default_encoding (str) – Default file content encoding when it is not provided, used to decode the tempfile contents from a text string into a binary string.
Returns: A list of str with the names of the files created.
-
setUp()¶
-