8000 improve doc with @berkerpeksag comments · python/cpython@93e0ef7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 93e0ef7

Browse files
eamanuJulienPalard
authored andcommitted
improve doc with @berkerpeksag comments
1 parent 7b5eae8 commit 93e0ef7

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Doc/library/unittest.mock.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,7 @@ patch.dict
15731573
values in the dictionary.
15741574

15751575
:func:`patch.dict` can be used as a context manager, decorator or class
1576-
decorator. When used as a class decorator :func:`patch.dict` honours
1577-
``patch.TEST_PREFIX`` for choosing which methods to wrap.
1576+
decorator.
15781577

15791578
>>> foo = {}
15801579
>>> @patch.dict(foo, {'newkey': 'newvalue'})
@@ -1583,12 +1582,22 @@ decorator. When used as a class decorator :func:`patch.dict` honours
15831582
>>> test()
15841583
>>> assert foo == {}
15851584

1585+
When used as a class decorator :func:`patch.dict` honours
1586+
``patch.TEST_PREFIX`` for choosing which methods to wrap. The patchers
1587+
recognise methods that start with ``'test'`` as being test methods.
1588+
If you want to use a different prefix for your test, you can inform the
1589+
patchers of the different prefix by setting ``patch.TEST_PREFIX``.
1590+
15861591
>>> import os
15871592
>>> import unittest
1593+
>>> patch.TEST_PREFIX = 'foo'
15881594
>>> @patch.dict('os.environ', {'newkey': 'newvalue'})
15891595
... class TestSample(unittest.TestCase):
1590-
... def test_sample(self):
1596+
... def foo_sample(self):
15911597
... self.assertEqual(os.environ['newkey'], 'newvalue')
1598+
...
1599+
... def test_sample2(self):
1600+
... self.assertNotIn('newkey', os.environ.keys())
15921601

15931602
.. versionchanged:: 3.8
15941603

0 commit comments

Comments
 (0)
0