pip install works inside the sandbox and installed packages are importable.
(
sandbox: Callable[..., Sandbox],
)
| 40 | |
| 41 | |
| 42 | def test_pip_install_in_sandbox( |
| 43 | sandbox: Callable[..., Sandbox], |
| 44 | ) -> None: |
| 45 | """pip install works inside the sandbox and installed packages are importable.""" |
| 46 | with sandbox(delete_on_exit=True) as sb: |
| 47 | install = sb.exec( |
| 48 | ["pip", "install", "--quiet", "cowsay"], |
| 49 | timeout_seconds=60, |
| 50 | ) |
| 51 | assert install.exit_code == 0, ( |
| 52 | f"pip install failed:\nstdout: {install.stdout}\nstderr: {install.stderr}" |
| 53 | ) |
| 54 | |
| 55 | # Verify the package is importable |
| 56 | verify = sb.exec( |
| 57 | ["python", "-c", "import cowsay; print(cowsay.char_names[0])"], |
| 58 | timeout_seconds=20, |
| 59 | ) |
| 60 | assert verify.exit_code == 0, ( |
| 61 | f"import failed:\nstdout: {verify.stdout}\nstderr: {verify.stderr}" |
| 62 | ) |
| 63 | assert verify.stdout.strip(), "Expected non-empty output from cowsay" |
| 64 | |
| 65 | |
| 66 | def test_uv_pip_install_in_sandbox( |