1212from codeflash .verification .verification_utils import TestConfig
1313
1414
15+ from pathlib import Path
16+ from codeflash .discovery .discover_unit_tests import discover_unit_tests
17+
1518def test_unit_test_discovery_pytest ():
1619 project_path = Path (__file__ ).parent .parent .resolve () / "code_to_optimize"
1720 tests_path = project_path / "tests" / "pytest"
@@ -1327,3 +1330,35 @@ def test_target():
13271330 should_process = analyze_imports_in_test_file (test_file , target_functions )
13281331
13291332 assert should_process is False
1333+
1334+
1335+
1336+ def test_discover_unit_tests_caching ():
1337+ tests_root = Path (__file__ ).parent .resolve () / "tests"
1338+ project_root_path = tests_root .parent .resolve ()
1339+
1340+ test_config = TestConfig (
1341+ tests_root = tests_root ,
1342+ project_root_path = project_root_path ,
1343+ test_framework = "pytest" ,
1344+ tests_project_rootdir = project_root_path ,
1345+ use_cache = False ,
1346+ )
1347+
1348+
1349+
1350+ non_cached_function_to_tests , non_cached_num_discovered_tests , non_cached_num_discovered_replay_tests = (
1351+ discover_unit_tests (test_config )
1352+ )
1353+ cache_config = TestConfig (
1354+ tests_root = tests_root ,
1355+ project_root_path = project_root_path ,
1356+ test_framework = "pytest" ,
1357+ tests_project_rootdir = project_root_path ,
1358+ use_cache = True ,
1359+ )
1360+ tests , num_discovered_tests , num_discovered_replay_tests = discover_unit_tests (cache_config )
1361+
1362+ assert non_cached_num_discovered_tests == num_discovered_tests
1363+ assert non_cached_function_to_tests == tests
1364+ assert non_cached_num_discovered_replay_tests == num_discovered_replay_tests
0 commit comments