Skip to content

Commit e433989

Browse files
committed
bugfix
1 parent a42c1a8 commit e433989

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,18 @@ def add_addopts_to_pyproject() -> None:
8888

8989

9090
@contextmanager
91-
def rename_conftest() -> None:
92-
conftest_file = find_conftest()
93-
tmp_conftest_file = Path(conftest_file + ".tmp")
91+
def rename_conftest(tests_path: Path) -> None:
92+
conftest_file = find_conftest(tests_path)
93+
tmp_conftest_file = None
9494
try:
9595
# Rename original file
96-
if conftest_file.exists():
96+
if conftest_file:
97+
tmp_conftest_file = Path(str(conftest_file) + ".tmp")
9798
conftest_file.rename(tmp_conftest_file)
9899
yield
99100
finally:
100101
# Restore original file
101-
if conftest_file.exists():
102+
if conftest_file:
102103
tmp_conftest_file.rename(conftest_file)
103104

104105

codeflash/code_utils/config_parser.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ def find_pyproject_toml(config_file: Path | None = None) -> Path:
3131
raise ValueError(msg)
3232

3333

34-
def find_conftest() -> Union[Path, None]:
34+
def find_conftest(tests_path: Path) -> Union[Path, None]:
3535
# Find the conftest file on the root of the project
3636
dir_path = Path.cwd()
37-
while dir_path != dir_path.parent:
38-
config_file = dir_path / "conftest.py"
37+
cur_path = tests_path
38+
while cur_path != dir_path:
39+
config_file = cur_path / "conftest.py"
3940
if config_file.exists():
4041
return config_file
4142
# Search for conftest.py in the parent directories
42-
dir_path = dir_path.parent
43+
cur_path = cur_path.parent
4344
return None
4445

4546

codeflash/discovery/discover_unit_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def discover_tests_pytest(
157157
project_root = cfg.project_root_path
158158

159159
tmp_pickle_path = get_run_tmp_file("collected_tests.pkl")
160-
with custom_addopts(), rename_conftest():
160+
with custom_addopts(), rename_conftest(tests_root):
161161
result = subprocess.run(
162162
[
163163
SAFE_SYS_EXECUTABLE,

codeflash/verification/test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import TYPE_CHECKING
77

88
from codeflash.cli_cmds.console import logger
9-
from codeflash.code_utils.code_utils import custom_addopts, get_run_tmp_file, rename_conftest
9+
from codeflash.code_utils.code_utils import custom_addopts, get_run_tmp_file
1010
from codeflash.code_utils.compat import IS_POSIX, SAFE_SYS_EXECUTABLE
1111
from codeflash.code_utils.config_consts import TOTAL_LOOPING_TIME
1212
from codeflash.code_utils.coverage_utils import prepare_coverage_files
@@ -23,7 +23,7 @@ def execute_test_subprocess(
2323
cmd_list: list[str], cwd: Path, env: dict[str, str] | None, timeout: int = 600
2424
) -> subprocess.CompletedProcess:
2525
"""Execute a subprocess with the given command list, working directory, environment variables, and timeout."""
26-
with custom_addopts(), rename_conftest():
26+
with custom_addopts():
2727
logger.debug(f"executing test run with command: {' '.join(cmd_list)}")
2828
return subprocess.run(cmd_list, capture_output=True, cwd=cwd, env=env, text=True, timeout=timeout, check=False)
2929

0 commit comments

Comments
 (0)