@@ -36,6 +36,7 @@ def run_behavioral_tests(
3636 verbose : bool = False ,
3737 pytest_target_runtime_seconds : int = TOTAL_LOOPING_TIME ,
3838 enable_coverage : bool = False ,
39+ enable_profiler : bool = False ,
3940) -> tuple [Path , subprocess .CompletedProcess , Path | None ]:
4041 if test_framework == "pytest" :
4142 test_files : list [str ] = []
@@ -109,6 +110,28 @@ def run_behavioral_tests(
109110 logger .debug (
110111 f"""Result return code: { results .returncode } , { "Result stderr:" + str (results .stderr ) if results .stderr else "" } """
111112 )
113+ if enable_profiler :
114+ coverage_database_file , coveragercfile = prepare_coverage_files ()
115+
116+ cov_erase = execute_test_subprocess (
117+ shlex .split (f"{ SAFE_SYS_EXECUTABLE } -m coverage erase" ), cwd = cwd , env = pytest_test_env
118+ ) # this cleanup is necessary to avoid coverage data from previous runs, if there are any,
119+ # then the current run will be appended to the previous data, which skews the results
120+ logger .debug (cov_erase )
121+ coverage_cmd = [SAFE_SYS_EXECUTABLE , "-m" , "coverage" , "run" , f"--rcfile={ coveragercfile .as_posix ()} " , "-m" ]
122+
123+ if pytest_cmd == "pytest" :
124+ coverage_cmd .extend (["pytest" ])
125+ else :
126+ coverage_cmd .extend (shlex .split (pytest_cmd , posix = IS_POSIX )[1 :])
127+
128+ results = execute_test_subprocess (
129+ coverage_cmd + common_pytest_args + result_args + test_files , cwd = cwd , env = pytest_test_env , timeout = 600
130+ )
131+ logger .debug (
132+ f"Result return code: { results .returncode } , "
133+ f"{ 'Result stderr:' + str (results .stderr ) if results .stderr else '' } "
134+ )
112135 elif test_framework == "unittest" :
113136 if enable_coverage :
114137 msg = "Coverage is not supported yet for unittest framework"
@@ -127,7 +150,6 @@ def run_behavioral_tests(
127150
128151 return result_file_path , results , coverage_database_file if enable_coverage else None
129152
130-
131153def run_benchmarking_tests (
132154 test_paths : TestFiles ,
133155 pytest_cmd : str ,
0 commit comments