Skip to main content
PyPI version Python versions See Build Status on AppVeyor

A fixture to support expect tests (golden tests) in pytest

This code was mostly copied from ezyang/expecttest who wrote an implementation for unittest.

Installation

You can install “pytest-expect-test” via pip from PyPI:

$ pip install pytest-expect-test

Usage

Start by writing your test, printing out any interesting output, and then calling expect with an empty string

# Function we are testing
def cumulative_sum(nums):
    cum_sum = 0
    result = []
    for num in nums:
        result.append(num+cum_sum)
        cum_sum += num
    return result


def test_simple(expect):
    print(cumulative_sum([2, 3, 5]))
    expect("""""")
    print(cumulative_sum([1, 5, 9]))
    expect("""""")

Then run:

$ pytest

Note that the test fails because we expected nothing to be printed (e.g. we passed an empty string to the expect function), but there was some text that was printed.

We can automatically fix these tests by running:

$ EXPECTTEST_ACCEPT=1 pytest

Our test will then be updated to look like:

def test_simple(expect):
    print(cumulative_sum([2, 3, 5]))
    expect("""\
[2, 5, 10]
""")
    print(cumulative_sum([1, 5, 9]))
    expect("""\
[1, 6, 15]
""")

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-expect-test” is free and open source software

This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Release files for pytest-expect-test 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-expect-test 0.1.0
File Size Uploaded
pytest-expect-test-0.1.0.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-expect-test 0.1.0
File Interpreter ABI Platform
pytest_expect_test-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / pytest-expect-test-0.1.0.tar.gz

Download URL pytest-expect-test-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6e0ba127acc514b438d9cb5386909517ee5d864ea78593b924281df91a3e3607
BLAKE2b-256 checksum
How to use checksums
2fbce0076616c5b6271ec8b2e2d9b739af53d1fc383e37a02bdf58a222b01ffb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release files / pytest_expect_test-0.1.0-py3-none-any.whl

Download URL pytest_expect_test-0.1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3566d910695ab1047eeb03a59b68f4eefe8b96dbf16cd6f377ed5de2ed383685
BLAKE2b-256 checksum
How to use checksums
6806b1dac7e5548e1220dc0f6af6e6b072b703dbe1a93d5f7923815b5d38dd77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page