最佳答案
我试图理解这两种模仿方法的方法之间的区别。有人能帮忙区分一下吗?对于本例,我使用 passlib 库。
from passlib.context import CryptContext
from unittest import mock
with mock.patch.object(CryptContext, 'verify', return_value=True) as foo1:
mycc = CryptContext(schemes='bcrypt_sha256')
mypass = mycc.encrypt('test')
assert mycc.verify('tesssst', mypass)
with mock.patch('passlib.context.CryptContext.verify', return_value=True) as foo2:
mycc = CryptContext(schemes='bcrypt_sha256')
mypass = mycc.encrypt('test')
assert mycc.verify('tesssst', mypass)