On Mon, Nov 19, 2012 at 7:11 AM, Ethan Jucovy <ethan.juc...@gmail.com>wrote:
> On Mon, Nov 19, 2012 at 1:07 AM, RjOllos <ry...@physiosonics.com> wrote: > >> When I put `print` statements inside a unit test case I don't see any >> output in the console window. Any idea of why this might be? >> >> I know it's not the most elegant way to debug, but sometimes the quickest >> way to get some info about a variable when debugging some Trac code, >> particularly since I'm still a beginning with python and not proficient >> with pdb and other tools that exist. >> > > Python testrunners like to swallow output from print statements, > unfortunately. Some also like to swallow pdb breakpoints. > > I believe the Right Way to do this sort of debugging in tests is to use > Python's logging framework. But I'm always too lazy to look this up. I > usually end up doing ``logfile = open("/tmp/test.log", "a"); print >> > logfile, "log message"; logfile.close();`` instead, and `tail -f > /tmp/test.log` in another console window while I run my tests. > Oh, the other Lazy Approach I sometimes use is to just bypass the testrunner and execute my test file directly with `python path/to/my/tests.py`. Depending on how the tests are written, this may or may not work. For example most of Trac core's tests do run properly this way -- `python trac/tests/perm.py` etc works fine. When it does work it's really convenient -- you're in a normal Python environment, you can print and pdb all you want, and also you can be really selective about which tests you're running. (When I'm doing this I will often just comment out lines in the `suite()` definition so that I'm only executing the test I'm debugging at the moment. Then I just need to remember to restore the full test suite before I do a final-real-test-run and commit.) I'm sure there are Right Ways to do these things too but as a bad habit I highly recommend this method. :-) -Ethan -- You received this message because you are subscribed to the Google Groups "Trac Development" group. 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.