
On 27 February 2012 23:23, Mark Janssen <dreamingforward@gmail.com> wrote:
Right. But you typically group a bunch of actions into a single "test". If a doctest fails in an early action then every line after that will probably fail - a single test failure will cause multiple *reported* failures.
Not a general solution - not all reprs are reversible (in fact very few are as a proportion of all objects).
I don't fully follow you, but it shouldn't be hard to add this to doctest and see if it is really useful.
Heh. When I'm adding new features to existing code it is very common for me to write a test that drops into the debugger after setting up some state - and potentially using the test infrastructure (fixtures, django test client perhaps, etc). So not being able to run a single test or drop into a debugger puts the kybosh on that. Michael
-- http://www.voidspace.org.uk/ May you do good and not evil May you find forgiveness for yourself and forgive others May you share freely, never taking more than you give. -- the sqlite blessing http://www.sqlite.org/different.html

On Mon, Feb 27, 2012 at 5:31 PM, Michael Foord <fuzzyman@gmail.com> wrote:
Just an implementation suggestion - Guido's suggestion of using sys.displayhook will work to change the repr of objects (I had never heard of it until then, and had to test to convince myself). Doctest needs reliable repr's more than reversable repr's, and you can create them using that. You'll still get a lot of <foobar.Foobar object at 0x391a9df> strings, which suck... but if you are committed to doctest then maybe better to provide good __repr__ methods on your custom objects! For doctest.js (where I implemented a number of changes I would have wanted for doctest in Python) I have found this sort of thing sufficient, but Javascript objects tend to be a little more bare and there aren't existing conventions for repr/print/etc, so I have some more flexibility in my implementation. Ian

On Tue, Feb 28, 2012 at 9:44 AM, Ian Bicking <ianb@colorstudy.com> wrote:
You can actually do some pretty cool doctest hacks via displayhook and excepthook. I created a hacked together doctest variant [1] years ago that could run doctests from ODT files and also pay attention to sys.excepthook/displayhook before deciding that the test had failed. [1] http://svn.python.org/view/sandbox/trunk/userref/ Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On Feb 27, 2012, at 05:44 PM, Ian Bicking wrote:
+1 even if you don't use doctests! I can't tell you how many times adding a useful repr has vastly improved debugging. I urge everyone to flesh out your reprs with a little bit of useful information so you can quickly identify your instances at a pdb prompt. Cheers, -Barry

On Mon, Feb 27, 2012 at 5:31 PM, Michael Foord <fuzzyman@gmail.com> wrote:
Just an implementation suggestion - Guido's suggestion of using sys.displayhook will work to change the repr of objects (I had never heard of it until then, and had to test to convince myself). Doctest needs reliable repr's more than reversable repr's, and you can create them using that. You'll still get a lot of <foobar.Foobar object at 0x391a9df> strings, which suck... but if you are committed to doctest then maybe better to provide good __repr__ methods on your custom objects! For doctest.js (where I implemented a number of changes I would have wanted for doctest in Python) I have found this sort of thing sufficient, but Javascript objects tend to be a little more bare and there aren't existing conventions for repr/print/etc, so I have some more flexibility in my implementation. Ian

On Tue, Feb 28, 2012 at 9:44 AM, Ian Bicking <ianb@colorstudy.com> wrote:
You can actually do some pretty cool doctest hacks via displayhook and excepthook. I created a hacked together doctest variant [1] years ago that could run doctests from ODT files and also pay attention to sys.excepthook/displayhook before deciding that the test had failed. [1] http://svn.python.org/view/sandbox/trunk/userref/ Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

On Feb 27, 2012, at 05:44 PM, Ian Bicking wrote:
+1 even if you don't use doctests! I can't tell you how many times adding a useful repr has vastly improved debugging. I urge everyone to flesh out your reprs with a little bit of useful information so you can quickly identify your instances at a pdb prompt. Cheers, -Barry
participants (4)
-
Barry Warsaw
-
Ian Bicking
-
Michael Foord
-
Nick Coghlan