How to debug unittests with pudb debugger?

I am having trouble debugging some unit tests with the pudb debugger .

The tests run fine with python, but I was not able to run them with pudb .

I highlighted the problem by referring to the following code sample:

 class Math: def pow(self, x, y): return x ** y import unittest class MathTest(unittest.TestCase): def testPow23(self): self.assertEquals(8, Math().pow(2, 3)) def testPow24(self): self.assertEquals(16, Math().pow(2, 4)) if __name__ == '__main__': unittest.main() 

Testing runs fine:

 $ python amodule.py . ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK 

But if it works through pudb, it gives me the output:

 ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK 

I tried using pudb amodule.py , as well as python -m pudb.run amodule.py , but it doesn’t matter - no tests are performed in one way or another.

Should I do something else to debug unit tests with pudb?

+8
python python-unittest pudb
source share
3 answers

Try placing a breakpoint on a useful line in your code:

 from pudb import set_trace; set_trace() 

The paths you tried to run may interfere with test detection and / or not run your script with __name__ '__main__' .

+7
source share

Since this is a popular question, I believe that I should also mention that most of the test tools that are running will require you to switch to the switch so that it cannot display standard output and input (usually this is -s ).

So remember to run pytest -s when using Pytest or nosetests -s for Nose, python manage.py test -s for Django tests, or check the documentation for your test run.

0
source share

You can set a breakpoint even easier:

import pudb; pu.db

0
source share

All Articles