Skip to main content

A plugin to use approvaltests with pytest

Project description

PyPI version Python versions See Build Status on GitHub Actions

A plugin to use approvaltests with pytest

Features

  • command line options to choose which reporter to use on approval test failure

  • define your own diff reporter to use on approval test failure

Requirements

approvaltests

Installation

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

$ pip install pytest-approvaltests

Usage

See also the documentation for approval tests

When your approval tests fail and you are working interactively, you might like it to open another diff tool than when you are on a CI server for example.

This plugin allows you to configure pytest with which diff tool to use when tests fail.

To set the default reporter to ‘PythonNative’, suitable for use on the command line:

pytest –approvaltests-use-reporter=’PythonNative’

To define your own diff reporter, perhaps a program with a rich GUI installed only on your developer workstation:

pytest –approvaltests-add-reporter=”diff_program”

The value for ‘approvaltests-add-reporter’ should be an executable program that can diff two files received as arguments on the command line like this:

diff_program filepath1 filepath2

if it takes additional arguments, add them with ‘approvaltests-add-reporter-args’:

pytest –approvaltests-add-reporter=”diff_program” –approvaltests-add-reporter-args=”arg1,arg2”

They will be inserted like this:

diff_program arg1 arg2 filepath1 filepath2

Tip for Jetbrains toolbox and PyCharm users

You can use PyCharm as a diff tool, which is convenient if you are also using it as an IDE. Especially if you’re using Toolbox, it can be difficult to find the actual executable to pass to pytest. You could try this while PyCharm is running:

ps -ef | grep PyCharm

If you’re lucky it will show the full path to the PyCharm that is executing. It may not be pretty. However, then you can configure pytest with arguments something like this:

–approvaltests-add-reporter-args=’diff’ –approvaltests-add-reporter=’/Users/emily/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/192.6262.63/PyCharm.app/Contents/MacOS/pycharm’

In PyCharm, you can create a new ‘run configuration’ (see the [documentation](https://www.jetbrains.com/help/pycharm/creating-and-editing-run-debug-configurations.html)). Add a configuration using the ‘+’ button, choose “python tests | pytest”. Add these arguments to set the reporter for pytest under ‘Additional Arguments’.

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-approvaltests” is free and open source software

Issues

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

Developer Notes

To release a new version on pypi:

python setup.py install

check it created an egg file under dist

python -m twine upload dist/pytest_approvaltests-<version>-py3.7.egg

You will need to enter a valid username and password for pypi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-approvaltests-0.2.3.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

pytest_approvaltests-0.2.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest-approvaltests-0.2.3.tar.gz.

File metadata

  • Download URL: pytest-approvaltests-0.2.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for pytest-approvaltests-0.2.3.tar.gz
Algorithm Hash digest
SHA256 4aec67d822c1c9cef22895001fd482182950b9a21a09a5ed3793139b31b5fcd6
MD5 ab69d7056b8a4c03d8d264792d3ac387
BLAKE2b-256 ad49d15a25450f8844651a15c2e199cfd0f8a4dae56a4d61cfc81bc57e4a510e

See more details on using hashes here.

File details

Details for the file pytest_approvaltests-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pytest_approvaltests-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for pytest_approvaltests-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ca4c5d3ee8af57b44ed8b4ccfcd4d1ae3d98e189976dc83be26f769ec43d6df
MD5 8ba52fe9ba897347265f5887fc9fd3f9
BLAKE2b-256 ba05eb1b3932686321f8521c89dad6085622c31f74f62a473b9070e1a521d8d8

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