Skip to main content

Match test output against patterns stored in files

Project description

What is this

Build Status Latest Release

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:


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):

    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/

Review the stored pattern file and add 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.

Files for pytest-matcher, version 1.3.2
Filename, size File type Python version Upload date Hashes
Filename, size pytest_matcher-1.3.2-py3.6.egg (10.5 kB) File type Egg Python version 3.6 Upload date Hashes View
Filename, size pytest-matcher-1.3.2.tar.gz (20.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page