@@ -174,29 +174,6 @@ def _slow_start(self, replica=False):
174
174
sleep (0.5 )
175
175
176
176
177
- def _is_test_result_ok (test_case ):
178
- # sources of solution:
179
- # 1. python versions 2.7 - 3.10, verified on 3.10, 3.7, 2.7, taken from:
180
- # https://tousu.in/qa/?qa=555402/unit-testing-getting-pythons-unittest-results-in-a-teardown-method&show=555403#a555403
181
- #
182
- # 2. python versions 3.11+ mixin, verified on 3.11, taken from: https://stackoverflow.com/a/39606065
183
-
184
- if hasattr (test_case , '_outcome' ): # Python 3.4+
185
- if hasattr (test_case ._outcome , 'errors' ):
186
- # Python 3.4 - 3.10 (These two methods have no side effects)
187
- result = test_case .defaultTestResult () # These two methods have no side effects
188
- test_case ._feedErrorsToResult (result , test_case ._outcome .errors )
189
- else :
190
- # Python 3.11+
191
- result = test_case ._outcome .result
192
- else : # Python 2.7, 3.0-3.3
193
- result = getattr (test_case , '_outcomeForDoCleanups' , test_case ._resultForDoCleanups )
194
-
195
- ok = all (test != test_case for test , text in result .errors + result .failures )
196
-
197
- return ok
198
-
199
-
200
177
class PostgresNodeExtended (testgres .PostgresNode ):
201
178
202
179
def __init__ (self , base_dir = None , * args , ** kwargs ):
@@ -396,8 +373,33 @@ def __init__(self, *args, **kwargs):
396
373
397
374
os .environ ["PGAPPNAME" ] = "pg_probackup"
398
375
376
+ def __is_test_result_ok (test_case ):
377
+ # sources of solution:
378
+ # 1. python versions 2.7 - 3.10, verified on 3.10, 3.7, 2.7, taken from:
379
+ # https://tousu.in/qa/?qa=555402/unit-testing-getting-pythons-unittest-results-in-a-teardown-method&show=555403#a555403
380
+ #
381
+ # 2. python versions 3.11+ mixin, verified on 3.11, taken from: https://stackoverflow.com/a/39606065
382
+
383
+ if not isinstance (test_case , unittest .TestCase ):
384
+ raise AssertionError ("test_case is not instance of unittest.TestCase" )
385
+
386
+ if hasattr (test_case , '_outcome' ): # Python 3.4+
387
+ if hasattr (test_case ._outcome , 'errors' ):
388
+ # Python 3.4 - 3.10 (These two methods have no side effects)
389
+ result = test_case .defaultTestResult () # These two methods have no side effects
390
+ test_case ._feedErrorsToResult (result , test_case ._outcome .errors )
391
+ else :
392
+ # Python 3.11+
393
+ result = test_case ._outcome .result
394
+ else : # Python 2.7, 3.0-3.3
395
+ result = getattr (test_case , '_outcomeForDoCleanups' , test_case ._resultForDoCleanups )
396
+
397
+ ok = all (test != test_case for test , text in result .errors + result .failures )
398
+
399
+ return ok
400
+
399
401
def tearDown (self ):
400
- if _is_test_result_ok ( self ):
402
+ if self . __is_test_result_ok ( ):
401
403
for node in self .nodes_to_cleanup :
402
404
node .cleanup ()
403
405
self .del_test_dir (self .module_name , self .fname )
0 commit comments