@@ -79,17 +79,26 @@ async def enterAsyncContext(self, cm):
79
79
return result
80
80
81
81
def _callSetUp (self ):
82
- self ._asyncioTestContext .run (self .setUp )
83
- self ._callAsync (self .asyncSetUp )
82
+ self ._setupAsyncioRunner ()
83
+ try :
84
+ self ._asyncioTestContext .run (self .setUp )
85
+ self ._callAsync (self .asyncSetUp )
86
+ except Exception :
87
+ # _callTearDown is not called when _callSetUp fails.
88
+ self ._tearDownAsyncioRunner ()
89
+ raise
84
90
85
91
def _callTestMethod (self , method ):
86
92
if self ._callMaybeAsync (method ) is not None :
87
93
warnings .warn (f'It is deprecated to return a value!=None from a '
88
94
f'test case ({ method } )' , DeprecationWarning , stacklevel = 4 )
89
95
90
96
def _callTearDown (self ):
91
- self ._callAsync (self .asyncTearDown )
92
- self ._asyncioTestContext .run (self .tearDown )
97
+ try :
98
+ self ._callAsync (self .asyncTearDown )
99
+ self ._asyncioTestContext .run (self .tearDown )
100
+ finally :
101
+ self ._tearDownAsyncioRunner ()
93
102
94
103
def _callCleanup (self , function , * args , ** kwargs ):
95
104
self ._callMaybeAsync (function , * args , ** kwargs )
@@ -125,18 +134,6 @@ def _tearDownAsyncioRunner(self):
125
134
runner = self ._asyncioRunner
126
135
runner .close ()
127
136
128
- def run (self , result = None ):
129
- self ._setupAsyncioRunner ()
130
- try :
131
- return super ().run (result )
132
- finally :
133
- self ._tearDownAsyncioRunner ()
134
-
135
- def debug (self ):
136
- self ._setupAsyncioRunner ()
137
- super ().debug ()
138
- self ._tearDownAsyncioRunner ()
139
-
140
137
def __del__ (self ):
141
138
if self ._asyncioRunner is not None :
142
139
self ._tearDownAsyncioRunner ()
0 commit comments