Skip to content

Standalone version of pytest's assertion introspection rewrite

License

Notifications You must be signed in to change notification settings

getslash/dessert

Repository files navigation

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.

About

Standalone version of pytest's assertion introspection rewrite

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages