Skip to content

Commit 4a17784

Browse files
committed
fix bug
1 parent 5eb5fac commit 4a17784

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

eval_protocol/cli_commands/local_test.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,16 @@ def local_test_command(args: argparse.Namespace) -> int:
9595
entry = getattr(args, "entry", None)
9696
if entry:
9797
if "::" in entry:
98-
file_part = entry.split("::", 1)[0]
98+
file_part, func_part = entry.split("::", 1)
9999
file_path = (
100100
file_part if os.path.isabs(file_part) else os.path.abspath(os.path.join(project_root, file_part))
101101
)
102-
pytest_target = entry
102+
# Convert to project-relative like the non-:: path
103+
try:
104+
rel = os.path.relpath(file_path, project_root)
105+
except Exception:
106+
rel = file_path
107+
pytest_target = f"{rel}::{func_part}"
103108
else:
104109
file_path = entry if os.path.isabs(entry) else os.path.abspath(os.path.join(project_root, entry))
105110
# Use path relative to project_root when possible

tests/test_cli_local_test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,36 @@ def _fake_run_docker(root: str, image_tag: str, pytest_target: str, run_extras=N
222222
"--cpus=2",
223223
"--add-host=host.docker.internal:host-gateway",
224224
]
225+
226+
227+
def test_local_test_normalizes_entry_with_selector(tmp_path, monkeypatch):
228+
project = tmp_path / "proj"
229+
project.mkdir()
230+
monkeypatch.chdir(project)
231+
232+
# Create a dummy test file
233+
test_file = project / "metric" / "test_sel_abs.py"
234+
test_file.parent.mkdir(parents=True, exist_ok=True)
235+
test_file.write_text("def test_dummy():\n assert True\n", encoding="utf-8")
236+
237+
abs_entry = f"{str(test_file)}::test_dummy"
238+
239+
from eval_protocol.cli_commands import local_test as lt
240+
241+
# Avoid Docker path
242+
monkeypatch.setattr(lt, "_find_dockerfiles", lambda root: [])
243+
244+
captured = {"target": ""}
245+
246+
def _fake_host(target: str) -> int:
247+
captured["target"] = target
248+
return 0
249+
250+
monkeypatch.setattr(lt, "_run_pytest_host", _fake_host)
251+
252+
args = SimpleNamespace(entry=abs_entry, ignore_docker=False, yes=True)
253+
rc = lt.local_test_command(args) # pyright: ignore[reportArgumentType]
254+
assert rc == 0
255+
# Expect project-relative path plus selector
256+
rel = os.path.relpath(str(test_file), str(project))
257+
assert captured["target"] == f"{rel}::test_dummy"

0 commit comments

Comments
 (0)