Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pytest-expect-test

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pytest-expect-test

A fixture to support expect tests in pytest

  • 0.1.0
  • PyPI
  • Socket score

Maintainers
1

================== pytest-expect-test

.. image:: https://img.shields.io/pypi/v/pytest-expect-test.svg :target: https://pypi.org/project/pytest-expect-test :alt: PyPI version

.. image:: https://img.shields.io/pypi/pyversions/pytest-expect-test.svg :target: https://pypi.org/project/pytest-expect-test :alt: Python versions

.. image:: https://ci.appveyor.com/api/projects/status/github/daninge98/pytest-expect-test?branch=master :target: https://ci.appveyor.com/project/daninge98/pytest-expect-test/branch/master :alt: See Build Status on AppVeyor

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

This code was mostly copied from ezyang/expecttest <https://github.com/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

.. code-block:: python

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

.. code-block:: python

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.

.. _Cookiecutter: https://github.com/audreyr/cookiecutter .. _@hackebrot: https://github.com/hackebrot .. _MIT: http://opensource.org/licenses/MIT .. _BSD-3: http://opensource.org/licenses/BSD-3-Clause .. _GNU GPL v3.0: http://www.gnu.org/licenses/gpl-3.0.txt .. _Apache Software License 2.0: http://www.apache.org/licenses/LICENSE-2.0 .. _cookiecutter-pytest-plugin: https://github.com/pytest-dev/cookiecutter-pytest-plugin .. _file an issue: https://github.com/daninge98/pytest-expect-test/issues .. _pytest: https://github.com/pytest-dev/pytest .. _tox: https://tox.readthedocs.io/en/latest/ .. _pip: https://pypi.org/project/pip/ .. _PyPI: https://pypi.org/project

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc