On Wednesday, November 21, 2012 12:15:20 AM UTC+1, RjOllos wrote:
>
> On Tue, Nov 20, 2012 at 3:06 PM, Steffen Hoffmann <hof...@web.de<javascript:>
> > wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>> [...]
>> I do add print statements to unit test quite often to speed-up debugging
>> recently. So I can confirm that they do work. In fact I've found them to
>> work most of the time, but not always. Still I've discovered other ways
>> to get to data from places, where print statements don't work.
>>
>
> One of the comments in your code suggests to me that you run unit tests 
> like: `PYTHONPATH=. python path/to/my/tests.py`. Is that always or nearly 
> always true? I've been running them using `PYTHONPATH=. python test`, so 
> I'll have to try both ways next time around now that I've seen Ethan's 
> comment.
>

"PYTHONPATH=. python setup.py test" you mean. Sure, as long as there is an 
entry for tests defined in setup.py. To avoid running the full suite each 
time, you can of course make each test file runnable. Either call it as 
suggested above, or using python -m mymodule.tests.mytest to execute the 
module by name.

If you want to inspect what happens in a test, then spend the half hour 
necessary to learn basic pdb. It is not scary at all, and most of the time 
you can just consider it an interactive interpreter.

HOWTO: Instead of littering with "print" just add a "import pdb; 
pdb.set_trace()" line to break into the interpreter on execution. At pdb 
prompt you can print whatever you like, change variables, run statements to 
check and whatever - using print statements or whatever you like. Enter 
'next' (or 'n') to execute next statement. Enter 'continue' (or just 'c') 
to exit debugging and continue running the code. Anyway, plenty of simple 
tutorials to google.

pdb works great for tests running in single thread and process - ie. don't 
use it for code being run by a web server...

:::simon

-- 
You received this message because you are subscribed to the Google Groups "Trac 
Development" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/trac-dev/-/rS7sW6KzqxUJ.
To post to this group, send email to trac-dev@googlegroups.com.
To unsubscribe from this group, send email to 
trac-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/trac-dev?hl=en.

Reply via email to