tags:

views:

120

answers:

2

I'm working in a project that recently switched to the py.test unittest framework. I was used to call my tests from Eclipse, so that I can use the debugger (e.g. placing breakpoints to analyze how a test failure develops). Now this is no longer possible, since the only way to run the tests is via the command line blackbox.

Is there some way to use py.test from within Python, so that one is not forced to drop out of the IDE? The tests should of course not be run in a separate process.

+1  A: 

I have not tried with eclipse, but as was suggested in a related question, it is possible to use the --pdb command line option with py.test. Maybe it is possible to configure eclipse that way.

However, calling the standard import pdb;pdb.set_trace() will not directly call the debugger. First it will issue an error which in turn will activate the debugger. This might or might not make things work differently.

Debilski
Thanks, I was aware of the `--pdb` switch. I think in this case pdb is controlled and started by py.test, which won't work for Eclipse (I want my running Eclipse to take over the debugging).
nikow
+2  A: 

I think I can now answer my own question, it's pretty simple:

import py
py.test.cmdline.main(args)

Then I can run this module and or start it with the integrated debugger.

args is the list of command line arguments, so for example to run only particular tests I can use something like:

args_str = "-k test_myfavorite"
py.test.cmdline.main(args_str.split(" "))
nikow