Fix #66: Document interaction with mock.patch
diff --git a/README.rst b/README.rst
index a77d3c4..d17e933 100644
--- a/README.rst
+++ b/README.rst
@@ -488,6 +488,22 @@
3. You're done!
+Using with ``mock.patch``
+-------------------------
+
+``parameterized`` can be used with ``mock.patch``, but the argument ordering
+can be confusing. The ``@mock.patch(...)`` decorator must come *below* the
+``@parameterized(...)``, and the mocked parameters must come *last*::
+
+ @mock.patch("os.getpid")
+ class TestOS(object):
+ @parameterized(...)
+ @mock.patch("os.fdopen")
+ @mock.patch("os.umask")
+ def test_method(self, param1, param2, ..., mock_umask, mock_fdopen, mock_getpid):
+ ...
+
+Note: the same holds true when using ``@parameterized.expand``.
FAQ
---
diff --git a/parameterized/test.py b/parameterized/test.py
index 7bc6b49..8842866 100644
--- a/parameterized/test.py
+++ b/parameterized/test.py
@@ -136,6 +136,21 @@
mock_fdopen._mock_name, mock_getpid._mock_name))
+@mock.patch("os.getpid")
+class TestParameterizedExpandWithNoExpand(object):
+ expect("generator", [
+ "test_patch_class_no_expand(42, 51, 'umask', 'getpid')",
+ ])
+
+ @parameterized([(42, 51)])
+ @mock.patch("os.umask")
+ def test_patch_class_no_expand(self, foo, bar, mock_umask, mock_getpid):
+ missing_tests.remove("test_patch_class_no_expand"
+ "(%r, %r, %r, %r)" %
+ (foo, bar, mock_umask._mock_name,
+ mock_getpid._mock_name))
+
+
class TestParameterizedExpandWithNoMockPatchForClass(TestCase):
expect([
"test_one_function_patch_decorator('foo1', 'umask')",
@@ -169,6 +184,18 @@
mock_fdopen._mock_name))
+class TestParameterizedExpandWithNoMockPatchForClassNoExpand(object):
+ expect("generator", [
+ "test_patch_no_expand(42, 51, 'umask')",
+ ])
+
+ @parameterized([(42, 51)])
+ @mock.patch("os.umask")
+ def test_patch_no_expand(self, foo, bar, mock_umask):
+ missing_tests.remove("test_patch_no_expand(%r, %r, %r)" %
+ (foo, bar, mock_umask._mock_name))
+
+
class TestParamerizedOnTestCase(TestCase):
expect([
"test_on_TestCase('foo0', bar=None)",