Skip to content

Commit f7b9d64

Browse files
acaprauclaude
andauthored
test(unit): reset EE state leaked by import side effects (#13844)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 40520ea commit f7b9d64

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

backend/tests/unit/conftest.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Unit-suite conftest.
2+
3+
Unit tests assume OSS resolution unless they opt into EE via the shared
4+
``enable_ee`` fixture (see ``backend/tests/conftest.py``).
5+
"""
6+
7+
from collections.abc import Generator
8+
9+
import pytest
10+
11+
from onyx.utils.variable_functionality import (
12+
fetch_versioned_implementation,
13+
global_version,
14+
)
15+
16+
17+
@pytest.fixture(autouse=True)
18+
def _reset_leaked_ee_state() -> Generator[None, None, None]:
19+
"""Undoes EE state leaked into the process by import side effects.
20+
21+
``set_is_ee_based_on_env_variable()`` runs at module level in ``onyx.main``
22+
and every ``background/celery/versioned_apps`` module, and flips the
23+
process-global EE flag whenever license enforcement is on (its default). A
24+
unit test whose import chain reaches one of those modules therefore silently
25+
switches every later test in the worker to EE resolution, breaking
26+
OSS-asserting tests order-dependently. Runs before ``enable_ee`` (autouse
27+
fixtures are instantiated first), so opting in still works.
28+
"""
29+
if global_version.is_ee_version():
30+
global_version.unset_ee()
31+
# Entries resolved while the flag was flipped point at EE
32+
# implementations; drop them along with the flag.
33+
fetch_versioned_implementation.cache_clear()
34+
yield

0 commit comments

Comments
 (0)