zhilts / mockito-python

Automatically exported from code.google.com/p/mockito-python
0 stars 0 forks source link

Spying on static methods #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
This might be a misunderstanding on my side regarding the use of spy(), but as 
in the test case below, I can't verify the execution of static methods:

from unittest2 import TestCase
from mockito import mock, when, unstub, spy, verify

class Foo(object):
    def foo(self):
        return self.bar()

    @staticmethod
    def bar():
        return 7

class TestMockito(TestCase):
    def test_spy(self):
        s = spy(Foo())
        s.foo()
        verify(s).foo()
        # i would expect those to work as well:
        verify(s).bar()
        verify(Foo).bar()

Original issue reported on code.google.com by christop...@gmail.com on 12 Aug 2010 at 9:23

GoogleCodeExporter commented 8 years ago
Actually, this does not work as well (no static method anymore):

class Foo(object):
    def foo(self):
        return self.baz()

    def baz(self):
        return 8

class TestMockito(TestCase):
    def test_spy(self):
        s = spy(Foo())
        s.foo()
        verify(s).foo()
        verify(s).baz()

Original comment by christop...@gmail.com on 12 Aug 2010 at 9:28

GoogleCodeExporter commented 8 years ago
Yes, it appears to be an issue. I will hopefuly dive into it this weekend. Busy 
times.
Feel free to fix and contribute a patch if you have time. 

Thanks,
Serhiy

Original comment by serhiy%oplakanets.com@gtempaccount.com on 1 Sep 2010 at 9:19