Skip to content
4 changes: 2 additions & 2 deletions .github/workflows/py-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Build Environment
run: make build
- name: Run Unit Tests
run: PYTHONPATH=".:$PYTHONPATH" poetry run pytest --forked -n auto -s ./tests/unit --cov=openhands --cov-branch
run: PYTHONPATH=".:$PYTHONPATH" poetry run pytest -n auto -s ./tests/unit --cov=openhands --cov-branch --cov-fail-under=72
env:
COVERAGE_FILE: ".coverage.${{ matrix.python_version }}"
- name: Store coverage file
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
run: poetry install --with dev,test
- name: Run Unit Tests
# Use base working directory for coverage paths to line up.
run: PYTHONPATH=".:$PYTHONPATH" poetry run --project=enterprise pytest --forked -n auto -s -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark ./enterprise/tests/unit --cov=enterprise --cov-branch
run: PYTHONPATH=".:$PYTHONPATH" poetry run --project=enterprise pytest -n auto -s -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark ./enterprise/tests/unit --cov=enterprise --cov-branch --cov-fail-under=72
env:
COVERAGE_FILE: ".coverage.enterprise.${{ matrix.python_version }}"
- name: Store coverage file
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ The `enterprise/` directory contains additional functionality that extends the o
**Running Enterprise Tests:**
```bash
# Enterprise unit tests (full suite)
PYTHONPATH=".:$PYTHONPATH" poetry run --project=enterprise pytest --forked -n auto -s -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark ./enterprise/tests/unit --cov=enterprise --cov-branch
PYTHONPATH=".:$PYTHONPATH" poetry run --project=enterprise pytest -n auto -s -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark ./enterprise/tests/unit --cov=enterprise --cov-branch

# Test specific modules (faster for development)
cd enterprise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def service() -> FeatureFlagService:

@pytest.fixture(autouse=True)
def _isolate_env_flag_defaults(monkeypatch):
"""Run each test against a clean env-flag registry + environment.
"""Run each test against a clean env-flag registry, environment, and caches.

The service consults a process-global ``_ENV_FLAG_DEFAULTS`` map and live
``os.environ`` for the env-var fallback. Without isolation, the seeded
Expand All @@ -52,6 +52,12 @@ def _isolate_env_flag_defaults(monkeypatch):
test mutating the registry via ``register_env_default`` would poison the
rest of the suite. Snapshot the registry and the relevant env vars, run
the test, then restore.

The service also uses class-level ``_cache`` and ``_global_cache`` dicts
that persist across instances and tests within a process. Without
``--forked`` (which gave each test its own process), the global snapshot
cached by one test leaks into the next via the 60-second TTL. Clear both
caches before and after each test.
"""
import server.services.feature_flag_service as ff_svc

Expand All @@ -62,6 +68,9 @@ def _isolate_env_flag_defaults(monkeypatch):
ff_svc._ENV_FLAG_DEFAULTS.clear()
for k in saved_env:
os.environ.pop(k, None)
# Clear class-level caches so snapshots from prior tests don't leak in.
FeatureFlagService._cache.clear()
FeatureFlagService._global_cache.clear()
yield
ff_svc._ENV_FLAG_DEFAULTS.clear()
ff_svc._ENV_FLAG_DEFAULTS.update(saved)
Expand All @@ -70,6 +79,9 @@ def _isolate_env_flag_defaults(monkeypatch):
os.environ.pop(k, None)
else:
os.environ[k] = v
# Clear caches again so mutations from this test don't leak forward.
FeatureFlagService._cache.clear()
FeatureFlagService._global_cache.clear()


def _patch_store(flag=None, rules=None):
Expand Down
Loading