Reputation: 27408
I followed the instructions on How to mock an import
but I'm having no success.
I have the following setup:
Class A
imports Class B
, and Class B
imports Class C
.
Class C
is the module I want to mock.
in test.py
:
import sys
from mock import Mock
sys.modules['C'] = Mock()
import A
print A.C.__name__ // this returns:
AttributeError: 'module' object has no attribute 'C'
Upvotes: 0
Views: 143
Reputation: 126
It should be A.B.C.__name__
like this:
import sys
from mock import Mock
sys.modules['C'] = Mock()
import A
print A.B.C.__name__
Upvotes: 3