Search code examples
pythonunit-testingpytestpython-mock

How patch multiple method of same object


I want to patch multiples method of same object. I am trying @patch.multiple('pdb.Pdb', do_continue=DEFAULT, do_step=DEFAULT, do_exit=DEFAULT) it throws error during running Test NameError: name 'DEFAULT' is not defined


Solution

  • unittest.mock.DEFAULT needs to be imported first. This will run without error:

    from unittest.mock import patch
    from unittest.mock import DEFAULT
    
    patch.multiple('pdb.Pdb', do_continue=DEFAULT, do_step=DEFAULT, do_exit=DEFAULT)