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

Failed to run a specific test with mock.patch decorator using nose2 #468

Closed
jethrolam opened this issue May 22, 2020 · 1 comment · Fixed by #472
Closed

Failed to run a specific test with mock.patch decorator using nose2 #468

jethrolam opened this issue May 22, 2020 · 1 comment · Fixed by #472

Comments

@jethrolam
Copy link

jethrolam commented May 22, 2020

This is my test file test_mock.py that minimally reproduces the failure:

import unittest
from unittest.mock import patch

class TestMock(unittest.TestCase):

    @patch("urllib3.PoolManager")
    def test_foo(self, mock_urllib3_poolmanager):
        pass

When I use nose2 to run all tests in this file. Everything works.

bash-4.2# nose2 test_mock
.
----------------------------------------------------------------------
Ran 1 test in 0.102s

OK

But when I use nose2 to select a specific test to run. It throws an error.

bash-4.2# nose2 test_mock.TestMock.test_foo
E
======================================================================
ERROR: test_mock.transplant_class.<locals>.C (test_foo)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/var/lang/lib/python3.7/unittest/mock.py", line 1256, in patched
    return func(*args, **keywargs)
TypeError: test_foo() missing 1 required positional argument: 'mock_urllib3_poolmanager'

----------------------------------------------------------------------
Ran 1 test in 0.087s

FAILED (errors=1)

Any insight is greatly appreciated. Thanks!

stefanholek added a commit to stefanholek/nose2 that referenced this issue Jul 27, 2020
…#468)

Stop loadTestsFromName from accepting class methods when they are
decorated (with e.g. mock.patch) and thus of types.FunctionType.

Also fixes issue with mock.patch'ed test case methods not working
under the multiprocess plugin (nose-devs#444).
@stefanholek
Copy link
Collaborator

The mock.patch issue has been fixed in PR #472.

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

Successfully merging a pull request may close this issue.

2 participants