Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug unittests with pudb debugger?

I am having some trouble trying to debug some unit tests through the pudb debugger.

The tests run fine with python, but I had no luck runnign them with pudb.

I isolated the problem, getting to the following sample code:

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()

The tests run fine:

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

OK

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

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

OK

I've tried running using pudb amodule.py and also with python -m pudb.run amodule.py, but it makes no difference -- no tests are run in one or another way.

Should I be doing something different to debug unit tests using pudb?

like image 524
Elias Dorneles Avatar asked Mar 14 '14 17:03

Elias Dorneles


People also ask

What is the way to debug code in test suite?

Debug mode​ Open a test case and switch to the Script view. Double-click on the leftmost side of the script editor to mark a breakpoint. A breakpoint is where Katalon Studio pauses the test execution for you to start debugging. Choose a browser for Debug from the main toolbar.

How do you debug a test case in Python?

Using pytest --pdb If you run your tests with pytest --pdb, it will automatically drop into a debugger on every test that fails or has an error of some kind. If you love using the REPL, IPython or Jupyter in your normal work, then you know how handy it is to be in an interactive environment when trying to fix errors!

How do you debug a unit test?

To start debugging: In the Visual Studio editor, set a breakpoint in one or more test methods that you want to debug. Because test methods can run in any order, set breakpoints in all the test methods that you want to debug. In Test Explorer, select the test method(s) and then choose Debug on the right-click menu.


1 Answers

You can set a breakpoint even easier by:

import pudb; pu.db

like image 154
Sławomir Lenart Avatar answered Oct 18 '22 16:10

Sławomir Lenart