2222logging .disable (logging .DEBUG )
2323
2424
25- def _sync_data (tmp_dir , test_parent_dir ):
26- data_dir = os .path .join (test_parent_dir , "php/data" )
27- tmp_data_dir = os .path .join (tmp_dir , "data" )
28-
29- if os .path .isdir (data_dir ):
30- os .makedirs (tmp_data_dir , exist_ok = True )
31- for data_file in os .listdir (data_dir ):
32- full_tmp_file = os .path .join (tmp_data_dir , data_file )
33- if os .path .exists (full_tmp_file ):
34- continue
35-
36- full_data_file = os .path .join (data_dir , data_file )
37- if os .path .isfile (full_data_file ):
38- shutil .copy (full_data_file , tmp_data_dir )
39- elif os .path .isdir (full_data_file ):
40- shutil .copytree (full_data_file , full_tmp_file )
41-
42-
43- def _get_tmp_folder_path (test_script_file ):
44- test_script_dir = os .path .dirname (os .path .realpath (test_script_file ))
45- tests_root_dir = test_script_dir
46- while not tests_root_dir .endswith ("python/tests" ):
47- tests_root_dir = os .path .dirname (tests_root_dir )
48- if "python/tests" not in tests_root_dir :
49- raise RuntimeError ("Can't find tests root dir" )
50-
51- python_tests_dir = os .path .dirname (tests_root_dir )
52- tmp_dir = os .path .join (python_tests_dir , "_tmp/" , test_script_dir [len (tests_root_dir ) + 1 :])
53- test_suite_name , _ = os .path .splitext (os .path .basename (test_script_file ))
54- working_dir = os .path .join (tmp_dir , "working_dir" )
55- artifacts_dir = os .path .join (tmp_dir , "artifacts" )
56- tmp_dir_root = os .path .join (artifacts_dir , "tmp_{}" .format (test_suite_name ))
57- return working_dir , tmp_dir_root , artifacts_dir , test_script_dir
58-
59-
60- def _make_test_tmp_dir (tmp_dir_root ):
25+ def make_test_tmp_dir (tmp_dir_root ):
6126 all_dirs = next (os .walk (tmp_dir_root ))[1 ]
6227 ppid = str (os .getppid ())
6328 for tmp_dir in all_dirs :
@@ -73,32 +38,28 @@ def _make_test_tmp_dir(tmp_dir_root):
7338 return test_tmp_dir
7439
7540
76- def _create_tmp_folders (test_script_file ):
77- kphp_build_working_dir , tmp_dir_root , artifacts_dir , test_script_dir = _get_tmp_folder_path (test_script_file )
78- for test_dir in (kphp_build_working_dir , tmp_dir_root , artifacts_dir ):
79- os .makedirs (test_dir , exist_ok = True )
80-
81- kphp_server_working_dir = _make_test_tmp_dir (tmp_dir_root )
82- _sync_data (kphp_server_working_dir , test_script_dir )
83- return kphp_build_working_dir , kphp_server_working_dir , artifacts_dir , test_script_dir
84-
85-
8641class BaseTestCase (TestCase ):
8742 kphp_build_working_dir = ""
8843 web_server_working_dir = ""
8944 artifacts_dir = ""
9045 test_dir = ""
9146
92- @classmethod
93- def _setup_tmp_folder (cls ):
94- script_file = sys .modules .get (cls .__module__ ).__file__
95- cls .kphp_build_working_dir , cls .web_server_working_dir , cls .artifacts_dir , cls .test_dir = \
96- _create_tmp_folders (script_file )
97-
98- @classmethod
99- def setup_class (cls ):
100- cls ._setup_tmp_folder ()
101- cls .custom_setup ()
47+ @pytest .fixture (scope = "class" )
48+ def setup_tmp_folder (
49+ self ,
50+ request : pytest .FixtureRequest ,
51+ working_dir : pathlib .Path ,
52+ kphp_server_working_dir : pathlib .Path ,
53+ artifacts_dir : pathlib .Path ,
54+ ):
55+ request .cls .kphp_build_working_dir = working_dir
56+ request .cls .web_server_working_dir = kphp_server_working_dir
57+ request .cls .artifacts_dir = artifacts_dir
58+ request .cls .test_dir = request .path .parent
59+
60+ @pytest .fixture (scope = "class" , autouse = True )
61+ def _base_setup (self , request : pytest .FixtureRequest , setup_tmp_folder ):
62+ request .cls .custom_setup ()
10263
10364 @classmethod
10465 def teardown_class (cls ):
@@ -190,7 +151,7 @@ class WebServerAutoTestCase(BaseTestCase):
190151 sanitizer_pattern = None
191152
192153
193- @pytest .fixture (scope = ' class' , autouse = True )
154+ @pytest .fixture (scope = " class" , autouse = True )
194155 def web_server_k2_builtins_updater (self , request , k2_builtin_calls ):
195156 yield
196157 if request .cls .should_use_k2 ():
@@ -333,15 +294,13 @@ def assertKphpNoTerminatedRequests(self):
333294 })
334295
335296
336- @pytest .fixture (scope = 'class' )
337- def kphp_compiler_k2_builtins (request , k2_builtin_calls ):
338- request .cls .k2_builtin_calls = k2_builtin_calls
339-
340-
341- @pytest .mark .usefixtures ('kphp_compiler_k2_builtins' )
342297class KphpCompilerAutoTestCase (BaseTestCase ):
343298 once_runner_trash_bin = []
344299
300+ @pytest .fixture (scope = "class" , autouse = True )
301+ def kphp_compiler_k2_builtins (self , request , k2_builtin_calls ):
302+ request .cls .k2_builtin_calls = k2_builtin_calls
303+
345304 def __init__ (self , method_name ):
346305 super ().__init__ (method_name )
347306 self .php_version = "php7.4"
@@ -364,7 +323,7 @@ def extra_class_teardown(cls):
364323
365324 @classmethod
366325 def custom_setup (cls ):
367- cls .kphp_build_working_dir = _make_test_tmp_dir (cls .kphp_build_working_dir )
326+ cls .kphp_build_working_dir = make_test_tmp_dir (cls .kphp_build_working_dir )
368327 cls .extra_class_setup ()
369328
370329 @classmethod
0 commit comments