I am using Mock to replace method from a class with a specific return value. It works very well, maybe a little too well... I do this (see below), but in the next test class, I reuse the password class without mocking, and the mock placed in that test is still effective.
from utils import password as pass_helper
class TestPassword(unittest.TestCase):
def setUp(self):
self.username = "user"
self.password = "Test_1234_pass"
pass_helper._get_password_from_keyboard = Mock(return_value=self.password)
def test_password(self):
password = pass_helper._get_password_from_keyboard(self.username)
self.assertEqual(password, self.password)
I tried undoing the mock in the TearDown method by doing something like this, but it does not work.
pass_helper._get_password_from_keyboard = pass_helper._get_password_from_keyboard
How can I restore the original functionnality of the class method?
unbound method xxx must be called with xxx instance as the first argument (got int instead)
– Afterdeck