Skip to content

Commit

Permalink
Fix #138: support for class-level mock.patch.multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
wolever committed Mar 27, 2023
1 parent 64295bf commit 8bc5b58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* Allow str, bytes, and any non-iterable input to be passed to
``@parameterized`` without wrapping in a tuple
(https://github.com/wolever/parameterized/pull/157)
* Fix class-level ``mock.patch.multiple``
(https://github.com/wolever/parameterized/issues/138; thanks @ArthurGW)

0.8.1 (2021-01-09)
* Add README and LICENSE to pypi sdist package
Expand Down
8 changes: 4 additions & 4 deletions parameterized/parameterized.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,12 @@ def parameterized_expand_wrapper(f, instance=None):
def param_as_standalone_func(cls, p, func, name):
if inspect.iscoroutinefunction(func):
@wraps(func)
async def standalone_func(*a):
return await func(*(a + p.args), **p.kwargs)
async def standalone_func(*a, **kw):
return await func(*(a + p.args), **p.kwargs, **kw)
else:
@wraps(func)
def standalone_func(*a):
return func(*(a + p.args), **p.kwargs)
def standalone_func(*a, **kw):
return func(*(a + p.args), **p.kwargs, **kw)

standalone_func.__name__ = name

Expand Down
20 changes: 14 additions & 6 deletions parameterized/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,29 @@ def test_mock_patch_standalone_function(foo, mock_umask):
)
)


@mock.patch.multiple("os", umask=mock.DEFAULT)
class TestParameterizedExpandWithMockPatchMultiple(TestCase):
expect([
"test_mock_patch_multiple_expand(42, 'umask', 'getpid')",
"test_mock_patch_multiple_expand_on_method(42, 'umask', 'getpid')",
"test_mock_patch_multiple_expand_on_class(16, 'umask')",
])

@parameterized.expand([(42, )])
@mock.patch.multiple("os", umask=mock.DEFAULT, getpid=mock.DEFAULT)
def test_mock_patch_multiple_expand(self, param, umask, getpid):
@mock.patch.multiple("os", getpid=mock.DEFAULT)
def test_mock_patch_multiple_expand_on_method(self, param, umask, getpid):
missing_tests.remove(
"test_mock_patch_multiple_expand(%r, %r, %r)" %(
"test_mock_patch_multiple_expand_on_method(%r, %r, %r)" %(
param, umask._mock_name, getpid._mock_name
)
)

@parameterized.expand([(16, )])
def test_mock_patch_multiple_expand_on_class(self, param, umask):
missing_tests.remove(
"test_mock_patch_multiple_expand_on_class(%r, %r)" %(
param, umask._mock_name,
)
)

expect("standalone", [
"test_mock_patch_multiple_standalone(42, 'umask', 'getpid')",
Expand Down Expand Up @@ -684,4 +692,4 @@ async def test_one_async_function(self, foo):
@mock.patch("os.umask")
async def test_one_async_function_patch_decorator(self, foo, mock_umask):
missing_tests.remove("test_one_async_function_patch_decorator(%r, %r)" %
(foo, mock_umask._mock_name))
(foo, mock_umask._mock_name))

0 comments on commit 8bc5b58

Please sign in to comment.