Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

too many positional argument for a mock with a spec to a twisted inlineCallback method #320

Closed
tardyp opened this issue Sep 6, 2015 · 1 comment

Comments

@tardyp
Copy link

tardyp commented Sep 6, 2015

Created a new issue, as this may not be exactly the same as #292

I got tests regression upgrading mock with buildbot test suite.

Digging a little bit more, I can find this is due to decoration with inlineCallbacks from twisted

from twisted.internet import defer
import unittest
import mock

def tested1(i, l):
    pass

class TestedClass2(object):
    def tested2(self, i, l):
        pass

class TestedClass3(object):
    @defer.inlineCallbacks
    def tested3(self, i, l):
        pass

class Test(unittest.TestCase):
    def test_tested1(self):
        tested1m = mock.Mock(spec=tested1)
        tested1m(1, [])
        tested1m.assert_called_with(1,[])

    def test_tested2(self):
        t = TestedClass2()
        t.tested2 = mock.Mock(spec=t.tested2)
        t.tested2(1, [])
        t.tested2.assert_called_with(1,[])

    def test_tested3(self):
        t = TestedClass3()
        t.tested3 = mock.Mock(spec=t.tested3)
        t.tested3(1, [])
        t.tested3.assert_called_with(1,[])

with relevent test results + downgrade result

# trial buildbot.testmock
buildbot.testmock
  Test
    test_tested1 ...                                                       [OK]
    test_tested2 ...                                                       [OK]
    test_tested3 ...                                                     [FAIL]

===============================================================================
[FAIL]
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/case.py", line 331, in run
    testMethod()
  File "/home/pierre/dev/bb/buildbot/master/buildbot/testmock.py", line 33, in test_tested3
    t.tested3.assert_called_with(1,[])
  File "/home/pierre/dev/bb/buildbot/sandbox/local/lib/python2.7/site-packages/mock/mock.py", line 937, in assert_called_with
    six.raise_from(AssertionError(_error_message(cause)), cause)
  File "/home/pierre/dev/bb/buildbot/sandbox/local/lib/python2.7/site-packages/six.py", line 692, in raise_from
    raise value
exceptions.AssertionError: Expected call: mock(1, [])
Actual call: mock(1, [])
too many positional arguments

buildbot.testmock.Test.test_tested3
-------------------------------------------------------------------------------
Ran 3 tests in 0.013s

FAILED (failures=1, successes=2)

# pip install -U mock==1.0.0
Downloading/unpacking mock==1.0.0
  Downloading mock-1.0.0.tar.gz (819kB): 819kB downloaded
  Running setup.py (path:/home/pierre/dev/bb/buildbot/sandbox/build/mock/setup.py) egg_info for package mock

Installing collected packages: mock
  Found existing installation: mock 1.3.0
    Uninstalling mock:
      Successfully uninstalled mock
  Running setup.py install for mock

Successfully installed mock
Cleaning up...

# trial buildbot.testmock
buildbot.testmock
  Test
    test_tested1 ...                                                       [OK]
    test_tested2 ...                                                       [OK]
    test_tested3 ...                                                       [OK]

-------------------------------------------------------------------------------
Ran 3 tests in 0.012s

PASSED (successes=3)
@rbtcollins
Copy link
Member

I believe this is fixed in trunk. Please reopen if it is not! [note that the fix is funcsigs 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants