Match test output against patterns stored in files
Project description
What is this
This is a pytest plugin which 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 test module name, test class name and/or test function name as following:
<base-dir>/<test-module-name>/[test-class-name/]<test-function-name>
Note, that for non-class test functions the test-class-name part is absent.
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. For the first pytest run it would fail, cuz 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 to your VCS.
See Also
Project details
Release history Release notifications | RSS feed
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.4.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15add07681acdbc68787a7d443f8842791d1e394e9db7953b5d3ef0c83393666 |
|
MD5 | b3eacdbcecad78d9c68b09e6f4e2aae1 |
|
BLAKE2b-256 | f2eed7de0374fae435660db652d5e64a9aee659fbdbcb488f9ed3b2d7664cb8a |