[Python-ideas] introspectable assertions

Chris Angelico rosuav at gmail.com
Thu Feb 19 08:31:10 CET 2015


On Thu, Feb 19, 2015 at 6:16 PM, Ronny Pfannschmidt
<opensource at ronnypfannschmidt.de> wrote:
> Hi,
>
> the idea is that if
> -> from __future__ import assertion_introspection
>
> then
> -> assert foo.bar(baz) == abc.def(), msg
> DetailedAssertionError: {msg}
> foo -> <foo...>
> baz -> <bar ...>
> foo.bar() -> <...>
> abc -> ...
> abc.def() -> ...
> foo.bar(baz) == abc.def() -> ...
>
> it would help introspection and testing utilities
>
> -- Ronny

So what you want is something which does the equivalent of REXX's
"trace i" for a failing assertion. That can actually be done by
MacroPy, which I've recently been looking into for other reasons.
Check out its "Tracing" facilities:

https://github.com/lihaoyi/macropy#tracing

There's even an example of this exact feature - a variant of assert
called require, which traces its results.

I haven't actually used that part of MacroPy, but check it out,
chances are it does what you want!

ChrisA


More information about the Python-ideas mailing list