8000 [PBCKP-304] moved _is_result_is_ok() into ProbackupTest class scope · postgrespro/pg_probackup@af4fb2e · GitHub
[go: up one dir, main page]

Skip to content

Commit af4fb2e

Browse files
author
Ivan Lazarev
committed
[PBCKP-304] moved _is_result_is_ok() into ProbackupTest class scope
1 parent f3f83b7 commit af4fb2e

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,29 +174,6 @@ def _slow_start(self, replica=False):
174174
sleep(0.5)
175175

176176

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-
200177
class PostgresNodeExtended(testgres.PostgresNode):
201178

202179
def __init__(self, base_dir=None, *args, **kwargs):
@@ -396,8 +373,33 @@ def __init__(self, *args, **kwargs):
396373

397374
os.environ["PGAPPNAME"] = "pg_probackup"
398375

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+
399401
def tearDown(self):
400-
if _is_test_result_ok(self):
402+
if self.__is_test_result_ok():
401403
for node in self.nodes_to_cleanup:
402404
node.cleanup()
403405
self.del_test_dir(self.module_name, self.fname)

0 commit comments

Comments
 (0)
0