8000 Add @berkerpeksag comments · python/cpython@2d6d232 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d6d232

Browse files
eamanuJulienPalard
authored andcommitted
Add @berkerpeksag comments
1 parent 93e0ef7 commit 2d6d232

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Doc/library/unittest.mock.rst

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

15751575
:func:`patch.dict` can be used as a context manager, decorator or class
1576-
decorator.
1576+
decorator:
15771577

1578+
>>> import patch
15781579
>>> foo = {}
15791580
>>> @patch.dict(foo, {'newkey': 'newvalue'})
15801581
... def test():
@@ -1583,21 +1584,19 @@ decorator.
15831584
>>> assert foo == {}
15841585

15851586
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``.
1587+
``patch.TEST_PREFIX`` (default to ``'test'``) for choosing which methods to wrap:
15901588

15911589
>>> import os
15921590
>>> import unittest
1593-
>>> patch.TEST_PREFIX = 'foo'
1591+
>>> from unittest.mock import patch
15941592
>>> @patch.dict('os.environ', {'newkey': 'newvalue'})
15951593
... class TestSample(unittest.TestCase):
1596-
... def foo_sample(self):
1594+
... def test_sample(self):
15971595
... self.assertEqual(os.environ['newkey'], 'newvalue')
1598-
...
1599-
... def test_sample2(self):
1600-
... self.assertNotIn('newkey', os.environ.keys())
1596+
1597+
If you want to use a different prefix for your test, you can inform the
1598+
patchers of the different prefix by setting ``patch.TEST_PREFIX``. For
1599+
more details about how to change the value of see :ref:`test-prefix`.
16011600

16021601
.. versionchanged:: 3.8
16031602

@@ -1816,6 +1815,8 @@ builtin :func:`ord`::
18161815
101
18171816

18181817

1818+
.. _test-prefix:
1819+
18191820
TEST_PREFIX
18201821
~~~~~~~~~~~
18211822

0 commit comments

Comments
 (0)
0