Skip to content

Commit 094dcae

Browse files
authored
Merge pull request #45 from codeflash-ai/coverage-config-bug-fix
fixed project config interfering with coverage config
2 parents 5728661 + 7a4ff2c commit 094dcae

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
@@ -225,13 +225,13 @@ class CoverageData:
225225

226226
@staticmethod
227227
def load_from_sqlite_database(
228-
database_path: Path, function_name: str, code_context: CodeOptimizationContext, source_code_path: Path
228+
database_path: Path, config_path: Path, function_name: str, code_context: CodeOptimizationContext, source_code_path: Path
229229
) -> CoverageData:
230230
"""Load coverage data from an SQLite database, mimicking the behavior of load_from_coverage_file."""
231231
from coverage import Coverage
232232
from coverage.jsonreport import JsonReporter
233233

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

236236
if not database_path.stat().st_size or not database_path.exists():
237237
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
@@ -1064,9 +1064,10 @@ def run_and_parse_tests(
10641064
unittest_loop_index: int | None = None,
10651065
) -> tuple[TestResults, CoverageData | None]:
10661066
coverage_database_file = None
1067+
coverage_config_file = None
10671068
try:
10681069
if testing_type == TestingMode.BEHAVIOR:
1069-
result_file_path, run_result, coverage_database_file = run_behavioral_tests(
1070+
result_file_path, run_result, coverage_database_file, coverage_config_file = run_behavioral_tests(
10701071
test_files,
10711072
test_framework=self.test_cfg.test_framework,
10721073
cwd=self.project_root,
@@ -1114,6 +1115,7 @@ def run_and_parse_tests(
11141115
source_file=self.function_to_optimize.file_path,
11151116
code_context=code_context,
11161117
coverage_database_file=coverage_database_file,
1118+
coverage_config_file=coverage_config_file,
11171119
)
11181120
return results, coverage_results
11191121

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)