Skip to main content

py.test plugin for regression tests

Project description

This pytest-plugin allows capturing of output of test functions which can be compared to the captured output from former runs. This is a common technique to start TDD if you have to refactor legacy code which ships without tests.

To install and activate this plugin you have to run:

$ pip install pytest-regtest

from your command line.

This py.test plugin provides a fixture named regtest for recording data by writing to this fixture, which behaves like an output stream:

def test_squares_up_to_ten(regtest):

    result = [i*i for i in range(10)]

    # one way to record output:
    print >> regtest, result

    # alternative method to record output:
    regtest.write("done")

We can redirect stdout to this stream using the regtest_redirect fixture:

def test_squares_up_to_ten(regtest_redirect):

    result = [i*i for i in range(10)]

    with regtest_redirect():
        print result

For recording the approved output, you run py.test with the –reset-regtest flag:

$ py.test --regtest-reset

The recorded output is written to text files in the subfolder _regtest_outputs next to your test scripts.

You can reset recorded output of files and functions individually as:

$ py.test --regtest-reset tests/test_00.py
$ py.test --regtest-reset tests/test_00.py::test_squares_up_to_ten

If you want to check that the testing function still produces the same output, you ommit the flag and run you tests as usual:

$ py.test

This shows diffs for the tests failing because the current and recorded output deviate.

To supress the diff and only see the stats use:

$ py.test --regtest-nodiff

If you want to see the recorded output on the commandline use:

$ py.test --regtest-tee -s

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

pytest-regtest-0.5.1.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file pytest-regtest-0.5.1.tar.gz.

File metadata

File hashes

Hashes for pytest-regtest-0.5.1.tar.gz
Algorithm Hash digest
SHA256 d5c5a94e8385604cab106e06f4d2e86ea398e17f84fee260b3d5c47e5a3aacc1
MD5 7f00dc8dbb639dda7ebe507eba2e230e
BLAKE2b-256 f1d0fd88157de1edd723baa9c79ced33882680f9952a9049d315187c90190e1d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page