fix(tests): replace patch.dict with monkeypatch to prevent env var leaks under xdist

patch.dict(os.environ) can leak TERMINAL_ENV across xdist workers,
causing test_code_execution tests to hit the Modal remote path.
This commit is contained in:
alt-glitch
2026-04-07 16:30:22 -07:00
parent b7903bca41
commit 04ee0ec0bc
2 changed files with 90 additions and 108 deletions
+11 -3
View File
@@ -18,10 +18,18 @@ import pytest
import json
import os
# Force local terminal backend for ALL tests in this file.
# Under xdist, another test may leak TERMINAL_ENV=modal/docker, sending
# execute_code down the remote path → modal.exception.AuthError.
os.environ["TERMINAL_ENV"] = "local"
@pytest.fixture(autouse=True)
def _force_local_terminal(monkeypatch):
"""Re-set TERMINAL_ENV=local before every test.
The module-level assignment above covers import time, but under xdist
another worker can overwrite os.environ between tests. monkeypatch
ensures each test starts (and ends) with the correct value.
"""
monkeypatch.setenv("TERMINAL_ENV", "local")
import sys
import time
import threading