Skip to main content

Assertion introspection via AST rewriting

Project description

Build Status Version

Overview

Dessert is a utility library enabling Python code to introspect assertions raised via the assert statement.

It is a standalone version of the introspection code from pytest, and all credit is due to Holger Krekel and the pytest developers for this code.

Usage

Using dessert is fairly simple:

>>> with open(tmp_filename, "w") as f:
...     _ = f.write("""
... def func():
...     def x():
...         return 1
...     def y():
...         return -1
...     assert y() == x()
... """)

>>> import emport
>>> import dessert
>>> with dessert.rewrite_assertions_context():
...     module = emport.import_file(tmp_filename)
>>> module.func() # doctest: +IGNORE_EXCEPTION_DETAIL +ELLIPSIS
Traceback (most recent call last):
    ...
    assert y() == x()
AssertionError: assert -1 == 1
+  where -1 = <function y at ...>()
+  and   1 = <function x at ...>()

Licence

Dessert is released under the MIT license. It is 99% based on pytest, which is released under the MIT license.

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

dessert-1.4.7.tar.gz (152.5 kB view details)

Uploaded Source

File details

Details for the file dessert-1.4.7.tar.gz.

File metadata

  • Download URL: dessert-1.4.7.tar.gz
  • Upload date:
  • Size: 152.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for dessert-1.4.7.tar.gz
Algorithm Hash digest
SHA256 d18c9d84d88956452636b17ccd7d9fac7552e44ca4f05439a961ce20ec0ed46f
MD5 1f34f33446d0432628f8d13c0ebf24b3
BLAKE2b-256 808adc1835004669a8b83a1a0d391726aa23c0226c318feb68a8506c4c59f21f

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