tg-me.com/pythonetc/728
Create:
Last Update:
Last Update:
Let's say, you have the following mock:
from unittest.mock import MockYou fully specified all attributes and methods it should have, and you pass it into the tested code, but then that code uses an attribute that you don't expect it to use:
user = Mock()
user.name = 'Guido'
user.ageInstead of failing with an
# <Mock name='mock.age' id='...'>
AttributeError
, the mock instead will create a new mock when its unspecified attribute is accessed. To fix it, you can (and should) use the unittest.mock.seal function (introduced in Python 3.7):from unittest.mock import seal
seal(user)
user.name
# 'Guido'
user.occupation
# AttributeError: mock.occupation
BY Python etc
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 280
Share with your friend now:
tg-me.com/pythonetc/728