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 a8c2980
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
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 a8c2980

Please sign in to comment.