Skip to content

Commit 0529788

Browse files
committed
push
1 parent 59b0b3f commit 0529788

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/test_decorators.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
mock_kwargs = {"a": 1, "b": 2, "c": 3}
2424

2525

26+
def removeMockResourceManagerInstances():
27+
for public_key in LangfuseResourceManager._instances.keys():
28+
if public_key != "pk-lf-1234567890":
29+
LangfuseResourceManager._instances.pop(public_key)
30+
31+
2632
def test_nested_observations():
2733
mock_name = "test_nested_observations"
2834
langfuse = get_client()
@@ -1144,6 +1150,9 @@ def level_1_function(*args, **kwargs):
11441150
assert len(trace_data.observations) == 3
11451151
assert trace_data.name == mock_name
11461152

1153+
# Reset instances to not leak to other test suites
1154+
removeMockResourceManagerInstances()
1155+
11471156

11481157
def test_multiproject_context_propagation_deep_nesting():
11491158
client1 = Langfuse() # Reads from environment
@@ -1204,6 +1213,9 @@ def level_1_function(*args, **kwargs):
12041213
]
12051214
assert set(levels) == {"1", "2", "3", "4"}
12061215

1216+
# Reset instances to not leak to other test suites
1217+
removeMockResourceManagerInstances()
1218+
12071219

12081220
def test_multiproject_context_propagation_override():
12091221
# Initialize two separate Langfuse instances
@@ -1255,6 +1267,9 @@ def level_1_function(*args, **kwargs):
12551267
assert len(trace_data.observations) == 2
12561268
assert trace_data.name == mock_name
12571269

1270+
# Reset instances to not leak to other test suites
1271+
removeMockResourceManagerInstances()
1272+
12581273

12591274
def test_multiproject_context_propagation_no_public_key():
12601275
# Initialize two separate Langfuse instances
@@ -1307,6 +1322,9 @@ def level_1_function(*args, **kwargs):
13071322
# Trace not found is also expected - tracing was completely disabled
13081323
pass
13091324

1325+
# Reset instances to not leak to other test suites
1326+
removeMockResourceManagerInstances()
1327+
13101328

13111329
@pytest.mark.asyncio
13121330
async def test_multiproject_async_context_propagation_basic():
@@ -1374,6 +1392,9 @@ async def async_level_1_function(*args, **kwargs):
13741392
]
13751393
assert all(async_flags)
13761394

1395+
# Reset instances to not leak to other test suites
1396+
removeMockResourceManagerInstances()
1397+
13771398

13781399
@pytest.mark.asyncio
13791400
async def test_multiproject_mixed_sync_async_context_propagation():
@@ -1443,6 +1464,9 @@ async def async_level_1_function(*args, **kwargs):
14431464
assert "sync" in types
14441465
assert "async" in types
14451466

1467+
# Reset instances to not leak to other test suites
1468+
removeMockResourceManagerInstances()
1469+
14461470

14471471
@pytest.mark.asyncio
14481472
async def test_multiproject_concurrent_async_context_isolation():
@@ -1531,6 +1555,9 @@ async def async_level_1_function(task_id, *args, **kwargs):
15311555
assert "async_level_2_function" in trace_2_names
15321556
assert "async_level_3_function" in trace_2_names
15331557

1558+
# Reset instances to not leak to other test suites
1559+
removeMockResourceManagerInstances()
1560+
15341561

15351562
@pytest.mark.asyncio
15361563
async def test_multiproject_async_generator_context_propagation():
@@ -1593,6 +1620,9 @@ async def async_consumer_function():
15931620
# This confirms that the async generator inherited the public key context
15941621
assert len(trace_data.observations) == 2
15951622

1623+
# Reset instances to not leak to other test suites
1624+
removeMockResourceManagerInstances()
1625+
15961626

15971627
@pytest.mark.asyncio
15981628
async def test_multiproject_async_context_exception_handling():
@@ -1658,4 +1688,5 @@ async def async_root_function(*args, **kwargs):
16581688
)
16591689
assert caught_obs is not None
16601690

1661-
LangfuseResourceManager.reset()
1691+
# Reset instances to not leak to other test suites
1692+
removeMockResourceManagerInstances()

0 commit comments

Comments
 (0)