I came across a strange bahviour of the patch
decorator in Fudge 1.0.3. It does not patch the module when importing classes via
from <module> import <class>
but works fine when importing
import <module>
with the corresponding code adaption.
Here's a minimalized setup:
mdle.py:
class Klaas(object):
def __init__(self):
# easyest way to signal this class has been instantiated accidently
raise Exception(">:[")
some.py (test not working):
from mdle import Klaas()
def instantiate():
instance = Klaas()
some.py (test working):
import mdle
def instantiate():
instance = mdle.Klaas()
some_test.py:
import unittest
import fudge
import some
class SomeTest(unittest.TestCase):
@fudge.patch("mdle.Klaas")
def test_somethingb(self, Klaas_mock):
klaas_inst = (Klaas_mock.expects_call()
.returns_fake())
# Receiving the exception
some.instantiate()
Should I patch in a different way? Is this a limitation of Fudge, or a bug?