Usage¶
To use the multilog feature, a test class just needs to inherit from the TestHelper class:
from pytest_multilog import TestHelper
class TestCustom(TestHelper):
def test_custom(self):
# Custom test implementation
...
The TestHelper class declares a logs fixture which will be automatically used by its children classes.
Log handlers¶
Added in version 1.7.0
Default handler¶
TestHelper class sets up a default logging handler which write each test logs to its own test_logs file.
This handler is handled with the following fixtures:
default_multilog_format: provides default handler log message formatdefault_multilog_date_format: provides default handler log date formatdefault_multilog_handler: provides default handler instance
Extra handlers¶
It is also possible to provide extra logging handlers by overriding the extra_multilog_handlers fixture. These handlers will be handled automatically by the logs fixture:
plugged in the logging system before running the test
after the test execution: properly closed and unplugged from the logging system
Checking logs¶
It is possible to verify if some strings are present in the current test_logs file, by using the check_logs method.
It takes as input argument:
either a simple string/Pattern or a list of strings/Patterns:
strings will be simply checked to be contained in the whole log
Patterns will be searched line by line (more flexible, but slower)
an optional timeout
a
check_orderparameter to verify patterns order (default if False)
The method will assert if all inputs are found in the log (within the expected timeout, if any).
By default, expected patterns order doesn’t matter.
If check_order parameter is set to True, patterns will be expected in the input order, and check will fail if the order doesn’t match.