Skip to content

Commit 7667215

Browse files
larrysingleton007ntkathole
authored andcommitted
fix: Reset the global security manager after the permissions fixture
The security_manager fixture in tests/unit/permissions/conftest.py calls set_security_manager(), which populates the module-level singleton in feast.permissions.security_manager, and never resets it. Every later test in the same pytest process that serves a request then runs against the leaked mock security manager and is rejected with 401 Unauthorized: running tests/unit/permissions/ together with tests/unit/test_feature_server.py in one process fails 26 feature server tests on master. CI masks this because pytest-xdist distributes the modules across workers. Convert the fixture to yield and reset via no_security_manager() on teardown, the same cleanup the integration auth tests already use. Signed-off-by: Larry Singleton <[email protected]>
1 parent c8628eb commit 7667215

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎sdk/python/tests/unit/permissions/conftest.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Iterator
12
from unittest.mock import MagicMock, Mock
23

34
import pytest
@@ -11,6 +12,7 @@
1112
from feast.permissions.policy import RoleBasedPolicy
1213
from feast.permissions.security_manager import (
1314
SecurityManager,
15+
no_security_manager,
1416
set_security_manager,
1517
)
1618
from feast.permissions.user import User
@@ -63,7 +65,7 @@ def users() -> list[User]:
6365

6466

6567
@pytest.fixture
66-
def security_manager() -> SecurityManager:
68+
def security_manager() -> Iterator[SecurityManager]:
6769
permissions = []
6870
permissions.append(
6971
Permission(
@@ -111,4 +113,9 @@ def security_manager() -> SecurityManager:
111113
registry.list_permissions = Mock(return_value=permissions)
112114
sm = SecurityManager(project="any", registry=registry)
113115
set_security_manager(sm)
114-
return sm
116+
yield sm
117+
# `set_security_manager` populates a module-level singleton that outlives
118+
# this fixture. Reset it, or every later test in the same process that
119+
# serves a request (e.g. the feature server tests) runs against this mock
120+
# security manager and is rejected with 401 Unauthorized.
121+
no_security_manager()

0 commit comments

Comments
 (0)