Skip to main content

Better exceptions

Project description

https://img.shields.io/pypi/v/pytest-exceptional.svg https://img.shields.io/pypi/pyversions/pytest-exceptional.svg See Build Status on Travis CI See Build Status on AppVeyor

Better pytest Exceptions

This plugin attempts to make richer pytest exceptions a snap to write. For example, consider the following exception:

class StartFire(pytest.Exception):
    __teststatus__ = 'fire', '🔥', ('FIRE', {'purple': True, 'bold': True})

    def toterminal(self, longrepr, tw):
        tw.line("FIRE! Please evacuate the building!")
        longrepr.toterminal(tw)

    def summary_header(self, header):
        return "Fire started during {}".format(header)

When this specific exception class is thrown, the pretty printing and result categorization is now in the hands of the exception, making it more straightforward than writing special purpose plugins.:

============================= test session starts ==============================
platform linux -- Python 3.6.0, pytest-3.0.7, py-1.4.32, pluggy-0.4.0
cachedir: .cache
rootdir: /home/simon/src/pytest-exceptional, inifile:
plugins: exceptional-0.1.0
collected 1 items

tests/test_fail_test.py::test_fire FIRE

________________________ Fire started during test_fire _________________________
FIRE! Please evacuate the building!

    def test_fire():
>       raise StartFire('There is a fire')
E       test_fail_test.StartFire: There is a fire

tests/test_fail_test.py:47: StartFire
============================ 1 fire in 0.02 seconds ============================

TODO

Provide more control over formatting and presentation without making the API too cumbersome. Still very much an early prototype and probably not close to a stable API.

Installation

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

$ pip install pytest-exceptional

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

Issues

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

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-exceptional-0.1.1.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file pytest-exceptional-0.1.1.tar.gz.

File metadata

File hashes

Hashes for pytest-exceptional-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0367f7e700f6e4c460b4a4912c0e849a8afb31105a7bbdf2133a89180dfc579c
MD5 d2255a0b637865c892946a0c1608d82a
BLAKE2b-256 b0d7bbd6c6ad512ff4b7389439055158dae7409ae8f9696bc6f7f7665e8facb2

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