I am having trouble to patch a class that is imported and set in a dictionary.
Given these files:
lib/
foo/
conf.py
foo.py
# conf.py
from .foo import Foo
CONF = {"class": Foo}
# foo.py
class Foo():
pass
Why Foo
is not MagicMock
in the CONF
variable? How to change this?
In [1]: from unittest.mock import patch
In [2]: with patch('lib.foo.conf.Foo') as mock:
2 from lib.foo.conf import *
3 print(f'CONF: {CONF}')
4 print(f'Foo: {Foo}')
CONF: {'class': <class 'lib.foo.foo.Foo'>}
Foo: <MagicMock name='Foo' id='140340109160656'>