Keep a ChangeLog
Project description
What is this
This is a pytest plugin that provides a couple of fixtures to match test output against patterns stored in files.
The plugin extends pytest with the following CLI options:
--pm-save-patterns – to store the output to a pattern file (instead of checking);
--pm-patterns-base-dir to specify a base directory, where to lookup pattern files.
Pattern files are stored in a base directory, and additional paths, based on the test module name, test class name, and test function name, are as follows:
<base-dir>/<test-module-name>/[test-class-name/]<test-function-name>[[<callspec-id>]]
Note, that for non-class test functions, the test-class-name part is absent. For parametrized tests, the callspec-id part containing %XX-escaped information about the parametrization is added.
Quick Start
The plugin provides expected_out and expected_err named fixture functions.
def test_foo(capfd, expected_out):
print('foo')
stdout, stderr = capfd.readouterr()
assert stdout == expected_out
Add pm-patterns-base-dir option to pytest.ini file and pytest section pointing, for example, to test/data/expected. The pyproject.toml example can be found in this repository. For the first pytest run, it would fail because there is no expected pattern file present. To write it, one can use pytest CLI:
$ pytest --pm-save-patterns test/test_foo.py::test_foo
Review the stored pattern file and add it to your VCS.
See Also
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_matcher-1.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2538a04f8d265acc5c9d9678189cf3d2fcacbe14dd501cfb50b46434240498a7 |
|
MD5 | 78433262ceeb3ffc70e61666e2f9be5c |
|
BLAKE2b-256 | 2fc742843317f55f453fdbc1af3845c6279b4f0c854ea071aee0e9a1e8508447 |