pytest with ipdb

Using ipdb with pytest requires the -s option.


import unittest

class ThingTest(unittest.TestCase):
    def test_the_thing(self):
        Tests the thing.

        import ipdb


Breakpoint is not caught when running pytest:

$ pipenv run pytest
=================== short test summary info ===================
FAILED - OSError: pytest: reading from stdin while output is captur...
====================== 1 failed in 0.38s ======================

The breakpoint is caught when running pytest with the -s option:

$ pipenv run pytest -s
===================== test session starts =====================
platform darwin -- Python 3.10.12, pytest-7.4.0, pluggy-1.2.0
rootdir: /tmp/example
collected 1 item                                       > /tmp/example/
     10         ipdb.set_trace()
---> 12         self.assertTrue(False)



Leave a Reply