Fixed test_webui only failing in nix_sandbox
This commit is contained in:
@@ -5,16 +5,23 @@ import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from cli import Cli
|
||||
from ports import PortFunction
|
||||
|
||||
from clan_cli.debug import breakpoint_container
|
||||
|
||||
@pytest.mark.timeout(10)
|
||||
|
||||
# @pytest.mark.timeout(10)
|
||||
def test_start_server(unused_tcp_port: PortFunction, temporary_home: Path) -> None:
|
||||
Cli()
|
||||
port = unused_tcp_port()
|
||||
|
||||
fifo = temporary_home / "fifo"
|
||||
os.mkfifo(fifo)
|
||||
|
||||
# Create a script called "firefox" in the temporary home directory that
|
||||
# writes "1" to the fifo. This is used to notify the test that the firefox has been
|
||||
# started.
|
||||
notify_script = temporary_home / "firefox"
|
||||
bash = shutil.which("bash")
|
||||
assert bash is not None
|
||||
@@ -26,11 +33,27 @@ echo "1" > {fifo}
|
||||
)
|
||||
notify_script.chmod(0o700)
|
||||
|
||||
# Add the temporary home directory to the PATH so that the script is found
|
||||
env = os.environ.copy()
|
||||
print(str(temporary_home.absolute()))
|
||||
env["PATH"] = ":".join([str(temporary_home.absolute())] + env["PATH"].split(":"))
|
||||
env["PATH"] = f"{temporary_home}:{env['PATH']}"
|
||||
|
||||
# Add build/src to PYTHONPATH so that the webui module is found in nix sandbox
|
||||
python_path = env.get("PYTHONPATH")
|
||||
if python_path:
|
||||
env["PYTHONPATH"] = f"/build/src:{python_path}"
|
||||
|
||||
breakpoint_container(
|
||||
cmd=[sys.executable, "-m", "clan_cli.webui", "--port", str(port)],
|
||||
env=env,
|
||||
work_dir=temporary_home,
|
||||
)
|
||||
|
||||
with subprocess.Popen(
|
||||
[sys.executable, "-m", "clan_cli.webui", "--port", str(port)], env=env
|
||||
[sys.executable, "-m", "clan_cli.webui", "--port", str(port)],
|
||||
env=env,
|
||||
stdout=sys.stderr,
|
||||
stderr=sys.stderr,
|
||||
text=True,
|
||||
) as p:
|
||||
try:
|
||||
with open(fifo) as f:
|
||||
|
||||
Reference in New Issue
Block a user