jeudi 17 septembre 2015

Mock an import from an import

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'

Aucun commentaire:

Enregistrer un commentaire