summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test
diff options
context:
space:
mode:
authorElena Oat <oat.elena@gmail.com>2019-12-08 20:14:38 (GMT)
committerChris Withers <chris@withers.org>2019-12-08 20:14:38 (GMT)
commitcd90a52983db34896a6335a572d55bdda274778f (patch)
tree601b917b63353a957a7763478d3a76480d9bb039 /Lib/unittest/test
parent28c91631c24e53713ad0e8a2bbae716373f5e53d (diff)
downloadcpython-cd90a52983db34896a6335a572d55bdda274778f.zip
cpython-cd90a52983db34896a6335a572d55bdda274778f.tar.gz
cpython-cd90a52983db34896a6335a572d55bdda274778f.tar.bz2
bpo-38669: patch.object now raises a helpful error (GH17034)
This means a clearer message is now shown when patch.object is called with two string arguments, rather than a class and a string argument.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r--Lib/unittest/test/testmock/testpatch.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/unittest/test/testmock/testpatch.py b/Lib/unittest/test/testmock/testpatch.py
index 0632d95..e065a2c 100644
--- a/Lib/unittest/test/testmock/testpatch.py
+++ b/Lib/unittest/test/testmock/testpatch.py
@@ -105,6 +105,10 @@ class PatchTest(unittest.TestCase):
self.assertEqual(Something.attribute, sentinel.Original,
"patch not restored")
+ def test_patchobject_with_string_as_target(self):
+ msg = "'Something' must be the actual object to be patched, not a str"
+ with self.assertRaisesRegex(TypeError, msg):
+ patch.object('Something', 'do_something')
def test_patchobject_with_none(self):
class Something(object):