Skip to content

Commit f3d3d8e

Browse files
committed
Merge branch 'coverage-config-bug-fix' into testgen-context-improvement
2 parents a224dbb + d80cfdb commit f3d3d8e

File tree

5 files changed

+13
-9
lines changed

5 files changed

+13
-9
lines changed

codeflash/models/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ class CoverageData:
232232

233233
@staticmethod
234234
def load_from_sqlite_database(
235-
database_path: Path, function_name: str, code_context: CodeOptimizationContext, source_code_path: Path
235+
database_path: Path, config_path: Path, function_name: str, code_context: CodeOptimizationContext, source_code_path: Path
236236
) -> CoverageData:
237237
"""Load coverage data from an SQLite database, mimicking the behavior of load_from_coverage_file."""
238238
from coverage import Coverage
239239
from coverage.jsonreport import JsonReporter
240240

241-
cov = Coverage(data_file=database_path, data_suffix=True, auto_data=True, branch=True)
241+
cov = Coverage(data_file=database_path,config_file=config_path, data_suffix=True, auto_data=True, branch=True)
242242

243243
if not database_path.stat().st_size or not database_path.exists():
244244
logger.debug(f"Coverage database {database_path} is empty or does not exist")

codeflash/optimization/function_optimizer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,10 @@ def run_and_parse_tests(
10651065
unittest_loop_index: int | None = None,
10661066
) -> tuple[TestResults, CoverageData | None]:
10671067
coverage_database_file = None
1068+
coverage_config_file = None
10681069
try:
10691070
if testing_type == TestingMode.BEHAVIOR:
1070-
result_file_path, run_result, coverage_database_file = run_behavioral_tests(
1071+
result_file_path, run_result, coverage_database_file, coverage_config_file = run_behavioral_tests(
10711072
test_files,
10721073
test_framework=self.test_cfg.test_framework,
10731074
cwd=self.project_root,
@@ -1115,6 +1116,7 @@ def run_and_parse_tests(
11151116
source_file=self.function_to_optimize.file_path,
11161117
code_context=code_context,
11171118
coverage_database_file=coverage_database_file,
1119+
coverage_config_file=coverage_config_file,
11181120
)
11191121
return results, coverage_results
11201122

codeflash/verification/parse_test_output.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ def parse_test_results(
478478
function_name: str | None,
479479
source_file: Path | None,
480480
coverage_database_file: Path | None,
481+
coverage_config_file: Path | None,
481482
code_context: CodeOptimizationContext | None = None,
482483
run_result: subprocess.CompletedProcess | None = None,
483484
unittest_loop_index: int | None = None,
@@ -523,6 +524,7 @@ def parse_test_results(
523524
all_args = True
524525
coverage = CoverageData.load_from_sqlite_database(
525526
database_path=coverage_database_file,
527+
config_path=coverage_config_file,
526528
source_code_path=source_file,
527529
code_context=code_context,
528530
function_name=function_name,

codeflash/verification/test_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +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-
) -> tuple[Path, subprocess.CompletedProcess, Path | None]:
39+
) -> tuple[Path, subprocess.CompletedProcess, Path | None, Path | None]:
4040
if test_framework == "pytest":
4141
test_files: list[str] = []
4242
for file in test_paths.test_files:
@@ -73,14 +73,14 @@ def run_behavioral_tests(
7373
pytest_test_env["PYTEST_PLUGINS"] = "codeflash.verification.pytest_plugin"
7474

7575
if enable_coverage:
76-
coverage_database_file, coveragercfile = prepare_coverage_files()
76+
coverage_database_file, coverage_config_file = prepare_coverage_files()
7777

7878
cov_erase = execute_test_subprocess(
7979
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m coverage erase"), cwd=cwd, env=pytest_test_env
8080
) # this cleanup is necessary to avoid coverage data from previous runs, if there are any,
8181
# then the current run will be appended to the previous data, which skews the results
8282
logger.debug(cov_erase)
83-
coverage_cmd = [SAFE_SYS_EXECUTABLE, "-m", "coverage", "run", f"--rcfile={coveragercfile.as_posix()}", "-m"]
83+
coverage_cmd = [SAFE_SYS_EXECUTABLE, "-m", "coverage", "run", f"--rcfile={coverage_config_file.as_posix()}", "-m"]
8484

8585
if pytest_cmd == "pytest":
8686
coverage_cmd.extend(["pytest"])
@@ -120,7 +120,7 @@ def run_behavioral_tests(
120120
msg = f"Unsupported test framework: {test_framework}"
121121
raise ValueError(msg)
122122

123-
return result_file_path, results, coverage_database_file if enable_coverage else None
123+
return result_file_path, results, coverage_database_file if enable_coverage else None, coverage_config_file if enable_coverage else None
124124

125125

126126
def run_benchmarking_tests(

tests/test_test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_sort(self):
4040
)
4141
fp.write(code.encode("utf-8"))
4242
fp.flush()
43-
result_file, process, coverage_pct = run_behavioral_tests(
43+
result_file, process, _, _ = run_behavioral_tests(
4444
test_files,
4545
test_framework=config.test_framework,
4646
cwd=Path(config.project_root_path),
@@ -84,7 +84,7 @@ def test_sort():
8484
)
8585
fp.write(code.encode("utf-8"))
8686
fp.flush()
87-
result_file, process, coverage_pct = run_behavioral_tests(
87+
result_file, process, _, _ = run_behavioral_tests(
8888
test_files,
8989
test_framework=config.test_framework,
9090
cwd=Path(config.project_root_path),

0 commit comments

Comments
 (0)