Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/datasmith/harbor_adapter/template/tests/pytest_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,10 @@ def run_pytest_and_collect(test_paths, extra_args=None, cwd=None):
sys.path.insert(0, repo_dir)

args = unique_paths + list(extra_args)
# TMPDIR is a host-mounted folder whose pytest-of-<user> can belong to another uid, which errors every test at setup.
if not any(a == "--basetemp" or a.startswith("--basetemp=") for a in args):
import tempfile as _tempfile
args.append("--basetemp=" + _tempfile.mkdtemp(prefix="fc-pytest-", dir="/tmp" if os.path.isdir("/tmp") else None))
exit_code = pytest.main(args=args, plugins=[plugin])
plugin.results["exit_code"] = int(exit_code)
plugin.results["selected_paths"] = unique_paths
Expand Down
11 changes: 11 additions & 0 deletions tests/docker/test_pytest_runner_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def test_new_test_file_from_the_agent_is_left_out_of_the_base_run(runner, repo:
assert (repo / "test_new.py").exists()


def test_tmp_path_works_when_the_temp_root_belongs_to_another_user(runner, repo: Path, tmp_path_factory, monkeypatch) -> None:
# memray/xarray: TMPDIR's pytest-of-<user> was owned by another uid, so every test errored at setup.
root = tmp_path_factory.mktemp("tmproot")
monkeypatch.setenv("TMPDIR", str(root))
monkeypatch.setattr(runner.os, "getuid", lambda: 12345, raising=False)
(repo / "test_tmp.py").write_text("def test_t(tmp_path):\n assert tmp_path.exists()\n")
res = runner.run_pytest_and_collect(["test_tmp.py"], cwd=str(repo))
assert [t["outcome"] for t in res["tests"] if t["when"] == "call"] == ["passed"]
assert not (root / "pytest-of-root").exists() and not any(root.glob("pytest-of-*"))


def test_no_base_results_is_not_ran(runner, repo: Path, monkeypatch) -> None:
real = runner._run
monkeypatch.setattr(runner, "_run", lambda cmd, cwd=None: (1, "", "boom") if cmd[0] == sys.executable else real(cmd, cwd))
Expand Down
Loading