Hi,
the idea is that if
-> from __future__ import assertion_introspection
then
-> assert foo.bar(baz) == abc.def(), msg
DetailedAssertionError: {msg}
foo ->
On Thu, Feb 19, 2015 at 6:16 PM, Ronny Pfannschmidt
Hi,
the idea is that if -> from __future__ import assertion_introspection
then -> assert foo.bar(baz) == abc.def(), msg DetailedAssertionError: {msg} foo ->
baz -> 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
On Thu, Feb 19, 2015 at 08:16:33AM +0100, Ronny Pfannschmidt wrote:
Hi,
the idea is that if
-> from __future__ import assertion_introspection
then
-> assert foo.bar(baz) == abc.def(), msg DetailedAssertionError: {msg} foo ->
baz -> foo.bar() -> <...> abc -> ... abc.def() -> ... foo.bar(baz) == abc.def() -> ... it would help introspection and testing utilities
I don't think we need a __future__ import, or to special case assert.
Python already has hooks for customizing tracebacks, see the cgitb
module. With it:
py> assert 23 == 24
AssertionError
Python 3.3.0rc3: /usr/local/bin/python3.3
Thu Feb 19 21:51:04 2015
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
/home/steve/<stdin> in <module>()
AssertionError:
__cause__ = None
__class__ =
On Thu, Feb 19, 2015 at 4:56 AM, Steven D'Aprano
Python already has hooks for customizing tracebacks, see the cgitb module.
Thanks for that reminder. I had forgotten completely about it. In the environment in which I work, we have an exception handler of last resort which logs the traceback to our log file, then exits. This would probably be a good place for me to log the return value of cgitb.text(sys.exc_info()) instead. Sure, it will often dump a fair amount of noise to the log file, but every once in awhile it will probably include a clue which is currently lost. Skip
participants (4)
-
Chris Angelico
-
Ronny Pfannschmidt
-
Skip Montanaro
-
Steven D'Aprano