Код: Выделить всё
class SomeClass:
def __init__(self):
# ..........
self.conn_instance = get_conn_to_external_api(...)
self.set_specific_attrs()
# ..........
def set_specific_attrs(self):
self.attr1 = "some conn-depent-attr"
self.attr2 = "another conn-depent-attr"
#....
self.attrn = "other attr"
Код: Выделить всё
def test_something(self, mocker):
mocker.patch("path-to-file/get_conn_to_external_api", some_patch_value)
# ...
instance = SomeClass()
# testing code
Подробнее здесь: https://stackoverflow.com/questions/791 ... -attribute