@@ -1573,8 +1573,9 @@ patch.dict
1573
1573
values in the dictionary.
1574
1574
1575
1575
:func: `patch.dict ` can be used as a context manager, decorator or class
1576
- decorator.
1576
+ decorator:
1577
1577
1578
+ >>> import patch
1578
1579
>>> foo = {}
1579
1580
>>> @ patch.dict(foo, {' newkey' : ' newvalue' })
1580
1581
... def test ():
@@ -1583,21 +1584,19 @@ decorator.
1583
1584
>>> assert foo == {}
1584
1585
1585
1586
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:
1590
1588
1591
1589
>>> import os
1592
1590
>>> import unittest
1593
- >>> patch. TEST_PREFIX = ' foo '
1591
+ >>> from unittest.mock import patch
1594
1592
>>> @ patch.dict(' os.environ' , {' newkey' : ' newvalue' })
1595
1593
... class TestSample (unittest .TestCase ):
1596
- ... def foo_sample (self ):
1594
+ ... def test_sample (self ):
1597
1595
... 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 `.
1601
1600
1602
1601
.. versionchanged :: 3.8
1603
1602
@@ -1816,6 +1815,8 @@ builtin :func:`ord`::
1816
1815
101
1817
1816
1818
1817
1818
+ .. _test-prefix :
1819
+
1819
1820
TEST_PREFIX
1820
1821
~~~~~~~~~~~
1821
1822
0 commit comments