Plugin Provided API
Fixture
- expected_out
- expected_err
This fixture provides an easy way to test captured
STDOUT
/STDERR
. To match a static output, one can use a trivialassert
:def test_foo(capfd, expected_out, expected_err): ... stdout, stderr = capfd.readouterr() assert expected_out == stdout assert expected_stderr == stderr
- expected_out.match(output: str) bool
- expected_err.match(output: str) bool
If the output has data changed from run to run (like timestamps or paths), one can edit the expected output file using regular expressions and use this function to match them. Please see Getting Started for more information about this topic.
def test_foo(capfd, expected_out, expected_err): ... stdout, _ = capfd.readouterr() assert expected_out.match(stdout) == True
Note
The plugin provides elaborate output on assert failure, but to make it work, one should use an explicit check for the
True
value of theexpected_out.match(…)
result.
- expected_yaml
This fixture provides an easy way to check if the output YAML data matches the expectations.
Todo
More docs on this!
Marker
- expect_suffix(*args: str, suffix: str)
If output may have system-specific content (e.g., different EOL styles), adding an arbitrary system-specific suffix to the pattern file makes storing different variants in separate files possible. Arguments to the marker will be
%XX
-escaped, dash-concatenated and prefixed with leading-
and then used as the{suffix}
placeholder of thepm-pattern-file-fmt
option.Usage example:
@pytest.mark.expect_suffix(suffix=platform.system()) def system_specific_test(capfd, expected_out): ... stdout, _ = capfd.readouterr() # Get content from `<base-dir>/.../system_specific-Linux.out` assert expected_out == stdout @pytest.mark.expect_suffix( f'py{sys.version_info.major}{sys.version_info.minor}' , f'pytest{pytest.version_tuple[0]} ) def python_specific_test(capfd, expected_out): ... stdout, _ = capfd.readouterr() # Get content from `<base-dir>/.../python_specific_test-py312-pytest8.out` assert expected_out == stdout