1
1
import sys
2
2
3
+ from collections .abc import Generator as DeferrableMethod
3
4
from unittest import TestCase
4
5
from unittest .case import _Outcome
5
6
from unittest .case import expectedFailure
6
7
7
- from ...utils import isiterable
8
8
from .runner import defer
9
9
10
10
__all__ = [
@@ -17,22 +17,22 @@ class DeferrableTestCase(TestCase):
17
17
18
18
def _callSetUp (self ):
19
19
deferred = self .setUp ()
20
- if isiterable (deferred ):
20
+ if isinstance (deferred , DeferrableMethod ):
21
21
yield from deferred
22
22
23
23
def _callTestMethod (self , method ):
24
24
deferred = method ()
25
- if isiterable (deferred ):
25
+ if isinstance (deferred , DeferrableMethod ):
26
26
yield from deferred
27
27
28
28
def _callTearDown (self ):
29
29
deferred = self .tearDown ()
30
- if isiterable (deferred ):
30
+ if isinstance (deferred , DeferrableMethod ):
31
31
yield from deferred
32
32
33
33
def _callCleanup (self , function , * args , ** kwargs ):
34
34
deferred = function (* args , ** kwargs )
35
- if isiterable (deferred ):
35
+ if isinstance (deferred , DeferrableMethod ):
36
36
yield from deferred
37
37
38
38
@staticmethod
@@ -71,22 +71,22 @@ def run(self, result=None):
71
71
72
72
with outcome .testPartExecutor (self ):
73
73
deferred = self ._callSetUp ()
74
- if isiterable (deferred ):
74
+ if isinstance (deferred , DeferrableMethod ):
75
75
yield from deferred
76
76
if outcome .success :
77
77
outcome .expecting_failure = expecting_failure
78
78
with outcome .testPartExecutor (self , isTest = True ):
79
79
deferred = self ._callTestMethod (testMethod )
80
- if isiterable (deferred ):
80
+ if isinstance (deferred , DeferrableMethod ):
81
81
yield from deferred
82
82
outcome .expecting_failure = False
83
83
with outcome .testPartExecutor (self ):
84
84
deferred = self ._callTearDown ()
85
- if isiterable (deferred ):
85
+ if isinstance (deferred , DeferrableMethod ):
86
86
yield from deferred
87
87
88
88
deferred = self .doCleanups ()
89
- if isiterable (deferred ):
89
+ if isinstance (deferred , DeferrableMethod ):
90
90
yield from deferred
91
91
for test , reason in outcome .skipped :
92
92
self ._addSkip (result , test , reason )
@@ -123,7 +123,7 @@ def doCleanups(self):
123
123
function , args , kwargs = self ._cleanups .pop ()
124
124
with outcome .testPartExecutor (self ):
125
125
deferred = self ._callCleanup (function , * args , ** kwargs )
126
- if isiterable (deferred ):
126
+ if isinstance (deferred , DeferrableMethod ):
127
127
yield from deferred
128
128
129
129
# return this for backwards compatibility
@@ -138,14 +138,14 @@ def doClassCleanups(cls):
138
138
function , args , kwargs = cls ._class_cleanups .pop ()
139
139
try :
140
140
deferred = function (* args , ** kwargs )
141
- if isiterable (deferred ):
141
+ if isinstance (deferred , DeferrableMethod ):
142
142
yield from deferred
143
143
except Exception :
144
144
cls .tearDown_exceptions .append (sys .exc_info ())
145
145
146
146
def __call__ (self , * args , ** kwds ):
147
147
deferred = self .run (* args , ** kwds )
148
- if isiterable (deferred ):
148
+ if isinstance (deferred , DeferrableMethod ):
149
149
yield from deferred
150
150
else :
151
151
return deferred
0 commit comments