Skip to content

Commit 7c61881

Browse files
authored
Merge pull request #2138 from codeflash-ai/fix/windows-junitxml-path
fix: use native path format for pytest subprocess args on Windows
2 parents 4da8e22 + aa98bc1 commit 7c61881

2 files changed

Lines changed: 17 additions & 25 deletions

File tree

codeflash/languages/python/support.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
CodeContext,
1616
FunctionFilterCriteria,
1717
HelperFunction,
18-
Language,
1918
ReferenceInfo,
2019
TestInfo,
2120
TestResult,
2221
)
22+
from codeflash.languages.language_enum import Language
2323
from codeflash.languages.registry import register_language
2424
from codeflash.models.function_types import FunctionParent
2525

@@ -48,8 +48,8 @@ def function_sources_to_helpers(sources: list[FunctionSource]) -> list[HelperFun
4848
qualified_name=fs.qualified_name,
4949
file_path=fs.file_path,
5050
source_code=fs.source_code,
51-
start_line=fs.jedi_definition.line if fs.jedi_definition else 1,
52-
end_line=fs.jedi_definition.line if fs.jedi_definition else 1,
51+
start_line=getattr(getattr(fs, "jedi_definition", None), "line", 1),
52+
end_line=getattr(getattr(fs, "jedi_definition", None), "line", 1),
5353
)
5454
for fs in sources
5555
]
@@ -119,7 +119,7 @@ def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
119119
)
120120

121121

122-
@register_language
122+
@register_language # type: ignore[arg-type] # PythonSupport satisfies LanguageSupport protocol structurally
123123
class PythonSupport:
124124
"""Python language support implementation.
125125
@@ -214,6 +214,7 @@ def load_coverage(
214214
) -> Any:
215215
from codeflash.verification.coverage_utils import CoverageUtils
216216

217+
assert coverage_config_file is not None
217218
return CoverageUtils.load_from_sqlite_database(
218219
database_path=coverage_database_file,
219220
config_path=coverage_config_file,
@@ -854,7 +855,7 @@ def compare_test_results(
854855
candidate_results_path: Path,
855856
project_root: Path | None = None,
856857
project_classpath: str | None = None,
857-
) -> tuple[bool, list]:
858+
) -> tuple[bool, list[Any]]:
858859
"""Compare test results between original and candidate code.
859860
860861
Args:
@@ -1017,7 +1018,7 @@ def instrument_source_for_line_profiler(
10171018
# This is handled through the existing infrastructure
10181019
return True
10191020

1020-
def parse_line_profile_results(self, line_profiler_output_file: Path) -> dict:
1021+
def parse_line_profile_results(self, line_profiler_output_file: Path) -> dict[str, Any]:
10211022
"""Parse line profiler output for Python.
10221023
10231024
Args:
@@ -1078,7 +1079,7 @@ def run_behavioral_tests(
10781079
from codeflash.code_utils.config_consts import TOTAL_LOOPING_TIME_EFFECTIVE
10791080
from codeflash.languages.python.static_analysis.coverage_utils import prepare_coverage_files
10801081
from codeflash.languages.python.test_runner import execute_test_subprocess
1081-
from codeflash.models.models import TestType
1082+
from codeflash.models.test_type import TestType
10821083

10831084
blocklisted_plugins = ["benchmark", "codspeed", "xdist", "sugar"]
10841085

@@ -1110,7 +1111,7 @@ def run_behavioral_tests(
11101111
common_pytest_args.append(f"--timeout={timeout}")
11111112

11121113
result_file_path = get_run_tmp_file(Path("pytest_results.xml"))
1113-
result_args = [f"--junitxml={result_file_path.as_posix()}", "-o", "junit_logging=all"]
1114+
result_args = [f"--junitxml={result_file_path}", "-o", "junit_logging=all"]
11141115

11151116
pytest_test_env = test_env.copy()
11161117
pytest_test_env["PYTEST_PLUGINS"] = "codeflash.verification.pytest_plugin"
@@ -1137,14 +1138,7 @@ def run_behavioral_tests(
11371138
shlex.split(f"{SAFE_SYS_EXECUTABLE} -m coverage erase"), cwd=cwd, env=pytest_test_env, timeout=30
11381139
)
11391140
logger.debug(cov_erase)
1140-
coverage_cmd = [
1141-
SAFE_SYS_EXECUTABLE,
1142-
"-m",
1143-
"coverage",
1144-
"run",
1145-
f"--rcfile={coverage_config_file.as_posix()}",
1146-
"-m",
1147-
]
1141+
coverage_cmd = [SAFE_SYS_EXECUTABLE, "-m", "coverage", "run", f"--rcfile={coverage_config_file}", "-m"]
11481142
coverage_cmd.extend(self.pytest_cmd_tokens(IS_POSIX))
11491143

11501144
blocklist_args = [f"-p no:{plugin}" for plugin in blocklisted_plugins if plugin != "cov"]
@@ -1201,7 +1195,7 @@ def run_benchmarking_tests(
12011195
pytest_args.append(f"--timeout={timeout}")
12021196

12031197
result_file_path = get_run_tmp_file(Path("pytest_results.xml"))
1204-
result_args = [f"--junitxml={result_file_path.as_posix()}", "-o", "junit_logging=all"]
1198+
result_args = [f"--junitxml={result_file_path}", "-o", "junit_logging=all"]
12051199
pytest_test_env = test_env.copy()
12061200
pytest_test_env["PYTEST_PLUGINS"] = "codeflash.verification.pytest_plugin"
12071201
blocklist_args = [f"-p no:{plugin}" for plugin in blocklisted_plugins]
@@ -1243,7 +1237,7 @@ def run_line_profile_tests(
12431237
if timeout is not None:
12441238
pytest_args.append(f"--timeout={timeout}")
12451239
result_file_path = get_run_tmp_file(Path("pytest_results.xml"))
1246-
result_args = [f"--junitxml={result_file_path.as_posix()}", "-o", "junit_logging=all"]
1240+
result_args = [f"--junitxml={result_file_path}", "-o", "junit_logging=all"]
12471241
pytest_test_env = test_env.copy()
12481242
pytest_test_env["PYTEST_PLUGINS"] = "codeflash.verification.pytest_plugin"
12491243
blocklist_args = [f"-p no:{plugin}" for plugin in blocklisted_plugins]
@@ -1258,7 +1252,7 @@ def run_line_profile_tests(
12581252

12591253
def generate_concolic_tests(
12601254
self, test_cfg: Any, project_root: Path, function_to_optimize: FunctionToOptimize, function_to_optimize_ast: Any
1261-
) -> tuple[dict, str]:
1255+
) -> tuple[dict[str, Any], str]:
12621256
import ast
12631257
import importlib.util
12641258
import subprocess
@@ -1281,7 +1275,7 @@ def generate_concolic_tests(
12811275
crosshair_available = importlib.util.find_spec("crosshair") is not None
12821276

12831277
start_time = time.perf_counter()
1284-
function_to_concolic_tests: dict = {}
1278+
function_to_concolic_tests: dict[str, Any] = {}
12851279
concolic_test_suite_code = ""
12861280

12871281
if not crosshair_available:

codeflash/languages/python/test_runner.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from codeflash.cli_cmds.console import logger
1212
from codeflash.code_utils.code_utils import custom_addopts
13-
from codeflash.code_utils.shell_utils import get_cross_platform_subprocess_run_args
1413
from codeflash.languages.registry import get_language_support
1514

1615
# Pattern to extract timing from stdout markers: !######...:<duration_ns>######!
@@ -92,11 +91,10 @@ def _ensure_runtime_files(project_root: Path, language: str = "javascript") -> N
9291

9392
def execute_test_subprocess(
9493
cmd_list: list[str], cwd: Path, env: dict[str, str] | None, timeout: int = 600
95-
) -> subprocess.CompletedProcess:
94+
) -> subprocess.CompletedProcess[str]:
9695
"""Execute a subprocess with the given command list, working directory, environment variables, and timeout."""
9796
logger.debug(f"executing test run with command: {' '.join(cmd_list)}")
9897
with custom_addopts():
99-
run_args = get_cross_platform_subprocess_run_args(
100-
cwd=cwd, env=env, timeout=timeout, check=False, text=True, capture_output=True
98+
return subprocess.run(
99+
cmd_list, cwd=cwd, env=env, timeout=timeout, check=False, text=True, capture_output=True, close_fds=False
101100
)
102-
return subprocess.run(cmd_list, **run_args) # noqa: PLW1510

0 commit comments

Comments
 (0)