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 arguments' error using mock > 1.0.1 #292

Closed
kvdb opened this issue Jul 21, 2015 · 6 comments
Closed

'too many positional arguments' error using mock > 1.0.1 #292

kvdb opened this issue Jul 21, 2015 · 6 comments

Comments

@kvdb
Copy link

kvdb commented Jul 21, 2015

When upgrading from mock1.0.1 to any higher version (tested 1.1.0 and 1.2.0), a test starts failing that used to work:

AssertionError: Expected call: mock(u'--magic', <Mock name='mock.name' id='139745351498256'>, u'--rate', 16000, u'--channels', 1, u'--bits', 16, u'--endian', u'little', u'--encoding', u'signed-integer', <Mock name=u'NamedTemporaryFile().name' id='139745351498064'>, u'trim', u'0.20', u'pad', u'0.20', u'0.00')
Actual call: mock(u'--magic', <Mock name='mock.name' id='139745351498256'>, u'--rate', 16000, u'--channels', 1, u'--bits', 16, u'--endian', u'little', u'--encoding', u'signed-integer', <Mock name=u'NamedTemporaryFile().name' id='139745351498064'>, u'trim', u'0.20', u'pad', u'0.20', u'0.00')
too many positional arguments
@rbtcollins
Copy link
Member

Could you supply some way to reproduce this issue for developers to use? a small self contained code exxample would be ideal. http://sscce.org/

@rbtcollins
Copy link
Member

Hi, I'm going to close this - its been 3 weeks without the question answered, and we can't act on it as it stands.

@tardyp
Copy link

tardyp commented Sep 6, 2015

here is a sscce to reproduce this:

import unittest
import mock

def tested1(i, l):
    pass

class TestedClass2(object):
    def tested2(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.testedmocked = mock.Mock(spec=t.tested2)
        t.testedmocked(1, [])
        t.testedmocked.assert_called_with(1,[])

here is the run:

# trial buildbot.testmock
buildbot.testmock
  Test
    test_tested1 ...                                                       [OK]
    test_tested2 ...                                                     [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 21, in test_tested2
    t.testedmocked.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_tested2
-------------------------------------------------------------------------------
Ran 2 tests in 0.012s

FAILED (failures=1, successes=1)

After downgrade:

# 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]

-------------------------------------------------------------------------------
Ran 2 tests in 0.013s

PASSED (successes=2)

@tardyp
Copy link

tardyp commented Sep 6, 2015

digging a little bit more, I realize that my initial attempt is erronous, as there is no self in my method.

My actual error is with a twisted inlineCallbacks decorated function

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 think this is testing-cabal/funcsigs#13

@rbtcollins
Copy link
Member

I believe this was fixed with 2.0.0 - please do reopen if it wasn't.

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

No branches or pull requests

3 participants