0

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'
Community
  • 1
  • 1
RustyShackleford
  • 25,262
  • 6
  • 22
  • 38

1 Answers1

3

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__ 
dmitryzv
  • 126
  • 6