1. Kumar McMillan
  2. fudge
  3. Issues
Issue #21 resolved

fudge.patch decorator

Victor Miroshnikov
created an issue

I'm trying to stub and check call through patch decorator.

zomg.py content: {{{


import time

class FooBar: def yay(self): return time.time()


tests.py content:



import fudge import zomg

@fudge.patch('time.time') def test_method(faketime): fake_time = fudge.Fake() faketime.is_callable().expects_call().returns(fake_time) h = zomg.FooBar() assert (h.yay() == fake_time) fudge.verify()

test_method() }}}

Thats what I get:

{{{ $ python tests.py Traceback (most recent call last): File "tests.py", line 12, in <module> test_method() File "fudge/patcher.py", line 85, in caller self.exit(None, None, None) File "fudge/patcher.py", line 112, in exit fudge.verify() File "fudge/init.py", line 129, in verify registry.verify() File "fudge/init.py", line 95, in verify exp.assert_called() File "fudge/init.py", line 435, in assert_called raise AssertionError("%s was not called" % (self)) AssertionError: fake:time.time() was not called }}}

Is this a normal behavior and I'm using fudge wrong way?

Comments (2)

  1. Kumar McMillan repo owner

    Hi. It looks like you are calling verify twice which is why you are seeing an error. It's actually passing the first time and failing the second because all call history was reset. This should work:

    import fudge
    import zomg
    def test_method(faketime):
            fake_time = fudge.Fake()
            h = zomg.FooBar()
            assert (h.yay() == fake_time)

    You can see it fail by commenting out your call to time.time() in zomg. I also removed is_callable() because it's implied by expects_call()

  2. Log in to comment