-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathconftest.py
More file actions
66 lines (56 loc) · 2.11 KB
/
conftest.py
File metadata and controls
66 lines (56 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""
Top-level pytest configuration
"""
import sys
import pytest
pytest_plugins = ["pytest_asyncio"]
# Keys polluted at module-level by tests/application/test_application_metrics.py
# and tests/application/test_application_settings.py. We save originals here
# (before any test module is imported) and restore them after collection so
# that tests/core/ and tests/prompts/ can import the real modules.
_POLLUTED_KEYS = [
"mcp",
"mcp.types",
"fastmcp",
"fastmcp.server",
"fastmcp.server.dependencies",
"pydantic",
"instana_client",
"instana_client.api",
"instana_client.api.application_metrics_api",
"instana_client.api.application_settings_api",
"instana_client.api_client",
"instana_client.configuration",
"instana_client.models",
"instana_client.models.get_application_metrics",
"instana_client.models.get_applications",
"instana_client.models.get_endpoints",
"instana_client.models.get_services",
"instana_client.models.application_config",
"instana_client.models.endpoint_config",
"instana_client.models.manual_service_config",
"instana_client.models.new_application_config",
"instana_client.models.new_manual_service_config",
"instana_client.models.service_config",
"src.prompts",
"src.core",
"src.core.utils",
]
_saved_modules: dict = {}
def pytest_configure(config):
"""Save sys.modules state before any test module is imported."""
for key in _POLLUTED_KEYS:
_saved_modules[key] = sys.modules.get(key)
def pytest_collection_finish(session):
"""Restore sys.modules after all test modules have been collected.
This runs after collection (when application test modules have been
imported and have polluted sys.modules) but before any test executes.
Tests/core/ and tests/prompts/ modules are already imported by this
point, so restoring sys.modules here only affects future imports
(e.g., lazy imports inside test functions).
"""
for key, original in _saved_modules.items():
if original is None:
sys.modules.pop(key, None)
else:
sys.modules[key] = original