9
9
from unittest .test .testmock import support
10
10
from unittest .test .testmock .support import SomeClass , is_instance
11
11
12
+ from test .test_importlib .util import uncache
12
13
from unittest .mock import (
13
14
NonCallableMock , CallableMixin , sentinel ,
14
15
MagicMock , Mock , NonCallableMagicMock , patch , _patch ,
@@ -1660,20 +1661,19 @@ def test_mock_calls_with_patch(self):
1660
1661
1661
1662
1662
1663
def test_patch_imports_lazily (self ):
1663
- sys .modules .pop ('squizz' , None )
1664
-
1665
1664
p1 = patch ('squizz.squozz' )
1666
1665
self .assertRaises (ImportError , p1 .start )
1667
1666
1668
- squizz = Mock ()
1669
- squizz .squozz = 6
1670
- sys .modules ['squizz' ] = squizz
1671
- p1 = patch ('squizz.squozz' )
1672
- squizz .squozz = 3
1673
- p1 .start ()
1674
- p1 .stop ()
1675
- self .assertEqual (squizz .squozz , 3 )
1667
+ with uncache ('squizz' ):
1668
+ squizz = Mock ()
1669
+ sys .modules ['squizz' ] = squizz
1676
1670
1671
+ squizz .squozz = 6
1672
+ p1 = patch ('squizz.squozz' )
1673
+ squizz .squozz = 3
1674
+ p1 .start ()
1675
+ p1 .stop ()
1676
+ self .assertEqual (squizz .squozz , 3 )
1677
1677
1678
1678
def test_patch_propogrates_exc_on_exit (self ):
1679
1679
class holder :
@@ -1696,7 +1696,12 @@ def with_custom_patch(target):
1696
1696
def test (mock ):
1697
1697
raise RuntimeError
1698
1698
1699
- self .assertRaises (RuntimeError , test )
1699
+ with uncache ('squizz' ):
1700
+ squizz = Mock ()
1701
+ sys .modules ['squizz' ] = squizz
1702
+
1703
+ self .assertRaises (RuntimeError , test )
1704
+
1700
1705
self .assertIs (holder .exc_info [0 ], RuntimeError )
1701
1706
self .assertIsNotNone (holder .exc_info [1 ],
1702
1707
'exception value not propgated' )
0 commit comments