1
- import logging
1
+ from __future__ import annotations
2
+
2
3
import os
3
4
import shutil
4
- import unittest
5
+ import pytest
6
+
5
7
from ...... import testgres
6
8
from ...pg_probackup2 .app import ProbackupApp
7
9
from ...pg_probackup2 .init_helpers import Init , init_params
8
10
from ..storage .fs_backup import FSTestBackupDir
9
11
10
12
11
- class TestUtils :
12
- @staticmethod
13
- def get_module_and_function_name (test_id ):
14
- try :
15
- module_name = test_id .split ('.' )[- 2 ]
16
- fname = test_id .split ('.' )[- 1 ]
17
- except IndexError :
18
- logging .warning (f"Couldn't get module name and function name from test_id: `{ test_id } `" )
19
- module_name , fname = test_id .split ('(' )[1 ].split ('.' )[1 ], test_id .split ('(' )[0 ]
20
- return module_name , fname
13
+ class ProbackupTest :
14
+ pg_node : testgres .PostgresNode
15
+
16
+ @pytest .fixture (autouse = True , scope = "function" )
17
+ def implicit_fixture (self , request : pytest .FixtureRequest ):
18
+ assert isinstance (request , pytest .FixtureRequest )
19
+ self .helper__setUp (request )
20
+ yield
21
+ self .helper__tearDown ()
22
+
23
+ def helper__setUp (self , request : pytest .FixtureRequest ):
24
+ assert isinstance (request , pytest .FixtureRequest )
21
25
26
+ self .helper__setup_test_environment (request )
27
+ self .helper__setup_test_paths ()
28
+ self .helper__setup_backup_dir ()
29
+ self .helper__setup_probackup ()
22
30
23
- class ProbackupTest (unittest .TestCase ):
24
- def setUp (self ):
25
- self .setup_test_environment ()
26
- self .setup_test_paths ()
27
- self .setup_backup_dir ()
28
- self .setup_probackup ()
31
+ def helper__setup_test_environment (self , request : pytest .FixtureRequest ):
32
+ assert isinstance (request , pytest .FixtureRequest )
29
33
30
- def setup_test_environment (self ):
31
34
self .output = None
32
35
self .cmd = None
33
36
self .nodes_to_cleanup = []
34
- self .module_name , self .fname = TestUtils . get_module_and_function_name ( self . id ())
37
+ self .module_name , self .fname = request . node . cls . __name__ , request . node . name
35
38
self .test_env = Init ().test_env ()
36
39
37
- def setup_test_paths (self ):
40
+ def helper__setup_test_paths (self ):
38
41
self .rel_path = os .path .join (self .module_name , self .fname )
39
42
self .test_path = os .path .join (init_params .tmp_path , self .rel_path )
40
43
os .makedirs (self .test_path , exist_ok = True )
41
44
self .pb_log_path = os .path .join (self .test_path , "pb_log" )
42
45
43
- def setup_backup_dir (self ):
44
- self .backup_dir = self .build_backup_dir ('backup' )
46
+ def helper__setup_backup_dir (self ):
47
+ self .backup_dir = self .helper__build_backup_dir ('backup' )
45
48
self .backup_dir .cleanup ()
46
49
47
- def setup_probackup (self ):
50
+ def helper__setup_probackup (self ):
48
51
self .pg_node = testgres .NodeApp (self .test_path , self .nodes_to_cleanup )
49
52
self .pb = ProbackupApp (self , self .pg_node , self .pb_log_path , self .test_env ,
50
53
auto_compress_alg = 'zlib' , backup_dir = self .backup_dir )
51
54
52
- def tearDown (self ):
55
+ def helper__tearDown (self ):
53
56
if os .path .exists (self .test_path ):
54
57
shutil .rmtree (self .test_path )
55
58
56
- def build_backup_dir (self , backup = 'backup' ):
59
+ def helper__build_backup_dir (self , backup = 'backup' ):
57
60
return FSTestBackupDir (rel_path = self .rel_path , backup = backup )
58
61
59
- class BasicTest (ProbackupTest ):
62
+
63
+ class TestBasic (ProbackupTest ):
60
64
def test_full_backup (self ):
61
65
# Setting up a simple test node
62
66
node = self .pg_node .make_simple ('node' , pg_options = {"fsync" : "off" , "synchronous_commit" : "off" })
@@ -75,8 +79,4 @@ def test_full_backup(self):
75
79
out = self .pb .validate ('node' , backup_id )
76
80
77
81
# Check if the backup is valid
78
- self .assertIn (f"INFO: Backup { backup_id } is valid" , out )
79
-
80
-
81
- if __name__ == "__main__" :
82
- unittest .main ()
82
+ assert f"INFO: Backup { backup_id } is valid" in out
0 commit comments