Skip to content

Commit bc94599

Browse files
author
Ivan Lazarev
committed
[PBCKP-304] auto tests cleanup added to ptrack_helper.py
1 parent fc8b890 commit bc94599

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

tests/cfs_backup.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
import shutil
55

66
from .helpers.cfs_helpers import find_by_extensions, find_by_name, find_by_pattern, corrupt_file
7-
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, is_test_result_ok
7+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
88

9-
module_name = 'cfs_backup'
109
tblspace_name = 'cfs_tblspace'
1110

1211

1312
class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
1413
# --- Begin --- #
1514
@unittest.skipUnless(ProbackupTest.enterprise, 'skip')
1615
def setUp(self):
17-
self.fname = self.id().split('.')[3]
1816
self.backup_dir = os.path.join(
19-
self.tmp_path, module_name, self.fname, 'backup')
17+
self.tmp_path, self.module_name, self.fname, 'backup')
2018
self.node = self.make_simple_node(
21-
base_dir="{0}/{1}/node".format(module_name, self.fname),
19+
base_dir="{0}/{1}/node".format(self.module_name, self.fname),
2220
set_replication=True,
2321
ptrack_enable=True,
2422
initdb_params=['--data-checksums'],
@@ -1159,12 +1157,6 @@ def test_broken_file_pg_compression_into_tablespace_dir(self):
11591157
)
11601158

11611159
# # --- End ---#
1162-
@unittest.skipUnless(ProbackupTest.enterprise, 'skip')
1163-
def tearDown(self):
1164-
module_name = self.id().split('.')[1]
1165-
fname = self.id().split('.')[3]
1166-
if is_test_result_ok(self):
1167-
self.del_test_dir(module_name, fname)
11681160

11691161

11701162
#class CfsBackupEncTest(CfsBackupNoEncTest):

tests/cfs_restore.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@
1313
import shutil
1414

1515
from .helpers.cfs_helpers import find_by_name
16-
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException, is_test_result_ok
17-
18-
19-
module_name = 'cfs_restore'
16+
from .helpers.ptrack_helpers import ProbackupTest, ProbackupException
2017

2118
tblspace_name = 'cfs_tblspace'
2219
tblspace_name_new = 'cfs_tblspace_new'
2320

2421

2522
class CfsRestoreBase(ProbackupTest, unittest.TestCase):
2623
def setUp(self):
27-
self.fname = self.id().split('.')[3]
28-
self.backup_dir = os.path.join(self.tmp_path, module_name, self.fname, 'backup')
24+
self.backup_dir = os.path.join(self.tmp_path, self.module_name, self.fname, 'backup')
2925

3026
self.node = self.make_simple_node(
31-
base_dir="{0}/{1}/node".format(module_name, self.fname),
27+
base_dir="{0}/{1}/node".format(self.module_name, self.fname),
3228
set_replication=True,
3329
initdb_params=['--data-checksums'],
3430
pg_options={
@@ -60,13 +56,6 @@ def setUp(self):
6056
def add_data_in_cluster(self):
6157
pass
6258

63-
@unittest.skipUnless(ProbackupTest.enterprise, 'skip')
64-
def tearDown(self):
65-
module_name = self.id().split('.')[1]
66-
fname = self.id().split('.')[3]
67-
if is_test_result_ok(self):
68-
self.del_test_dir(module_name, fname)
69-
7059

7160
class CfsRestoreNoencEmptyTablespaceTest(CfsRestoreBase):
7261
# @unittest.expectedFailure
@@ -214,7 +203,7 @@ def test_restore_from_fullbackup_to_new_location(self):
214203
self.node.cleanup()
215204
shutil.rmtree(self.get_tblspace_path(self.node, tblspace_name))
216205

217-
node_new = self.make_simple_node(base_dir="{0}/{1}/node_new_location".format(module_name, self.fname))
206+
node_new = self.make_simple_node(base_dir="{0}/{1}/node_new_location".format(self.module_name, self.fname))
218207
node_new.cleanup()
219208

220209
try:
@@ -257,7 +246,7 @@ def test_restore_from_fullbackup_to_new_location_5_jobs(self):
257246
self.node.cleanup()
258247
shutil.rmtree(self.get_tblspace_path(self.node, tblspace_name))
259248

260-
node_new = self.make_simple_node(base_dir="{0}/{1}/node_new_location".format(module_name, self.fname))
249+
node_new = self.make_simple_node(base_dir="{0}/{1}/node_new_location".format(self.module_name, self.fname))
261250
node_new.cleanup()
262251

263252
try:

tests/helpers/ptrack_helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ class ProbackupTest(object):
204204

205205
def __init__(self, *args, **kwargs):
206206
super(ProbackupTest, self).__init__(*args, **kwargs)
207+
208+
if isinstance(self, unittest.TestCase):
209+
self.module_name = self.id().split('.')[1]
210+
self.fname = self.id().split('.')[3]
211+
207212
if '-v' in argv or '--verbose' in argv:
208213
self.verbose = True
209214
else:
@@ -367,6 +372,13 @@ def __init__(self, *args, **kwargs):
367372

368373
os.environ["PGAPPNAME"] = "pg_probackup"
369374

375+
def tearDown(self):
376+
if isinstance(self, unittest.TestCase):
377+
module_name = self.id().split('.')[1]
378+
fname = self.id().split('.')[3]
379+
if is_test_result_ok(self):
380+
self.del_test_dir(module_name, fname)
381+
370382
@property
371383
def pg_config_version(self):
372384
return self.version_to_num(

0 commit comments

Comments
 (0)