Fix: test_map_api.py DB isolation — set CANTEEN_DB_PATH inside client fixture
Previously relied on module-level env var which got overwritten when frontend tests' conftest.py test_db_path fixture ran first. Now explicitly sets env var inside client fixture + invalidates caches before import. Also fixed importlib order.
This commit is contained in:
Binary file not shown.
@@ -30,13 +30,15 @@ def clean_db():
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def client():
|
def client():
|
||||||
|
# Ensure isolated DB path (module-level env may be overwritten by other tests)
|
||||||
|
os.environ["CANTEEN_DB_PATH"] = str(TEST_DB)
|
||||||
_clean_db()
|
_clean_db()
|
||||||
|
import importlib
|
||||||
|
importlib.invalidate_caches()
|
||||||
for mod in list(sys.modules.keys()):
|
for mod in list(sys.modules.keys()):
|
||||||
if mod == "server" or mod.startswith("server."):
|
if mod == "server" or mod.startswith("server."):
|
||||||
del sys.modules[mod]
|
del sys.modules[mod]
|
||||||
import server
|
import server
|
||||||
import importlib
|
|
||||||
importlib.invalidate_caches()
|
|
||||||
with TestClient(server.app) as tc:
|
with TestClient(server.app) as tc:
|
||||||
yield tc
|
yield tc
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user