|
23 | 23 | mock_kwargs = {"a": 1, "b": 2, "c": 3} |
24 | 24 |
|
25 | 25 |
|
| 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 | + |
26 | 32 | def test_nested_observations(): |
27 | 33 | mock_name = "test_nested_observations" |
28 | 34 | langfuse = get_client() |
@@ -1144,6 +1150,9 @@ def level_1_function(*args, **kwargs): |
1144 | 1150 | assert len(trace_data.observations) == 3 |
1145 | 1151 | assert trace_data.name == mock_name |
1146 | 1152 |
|
| 1153 | + # Reset instances to not leak to other test suites |
| 1154 | + removeMockResourceManagerInstances() |
| 1155 | + |
1147 | 1156 |
|
1148 | 1157 | def test_multiproject_context_propagation_deep_nesting(): |
1149 | 1158 | client1 = Langfuse() # Reads from environment |
@@ -1204,6 +1213,9 @@ def level_1_function(*args, **kwargs): |
1204 | 1213 | ] |
1205 | 1214 | assert set(levels) == {"1", "2", "3", "4"} |
1206 | 1215 |
|
| 1216 | + # Reset instances to not leak to other test suites |
| 1217 | + removeMockResourceManagerInstances() |
| 1218 | + |
1207 | 1219 |
|
1208 | 1220 | def test_multiproject_context_propagation_override(): |
1209 | 1221 | # Initialize two separate Langfuse instances |
@@ -1255,6 +1267,9 @@ def level_1_function(*args, **kwargs): |
1255 | 1267 | assert len(trace_data.observations) == 2 |
1256 | 1268 | assert trace_data.name == mock_name |
1257 | 1269 |
|
| 1270 | + # Reset instances to not leak to other test suites |
| 1271 | + removeMockResourceManagerInstances() |
| 1272 | + |
1258 | 1273 |
|
1259 | 1274 | def test_multiproject_context_propagation_no_public_key(): |
1260 | 1275 | # Initialize two separate Langfuse instances |
@@ -1307,6 +1322,9 @@ def level_1_function(*args, **kwargs): |
1307 | 1322 | # Trace not found is also expected - tracing was completely disabled |
1308 | 1323 | pass |
1309 | 1324 |
|
| 1325 | + # Reset instances to not leak to other test suites |
| 1326 | + removeMockResourceManagerInstances() |
| 1327 | + |
1310 | 1328 |
|
1311 | 1329 | @pytest.mark.asyncio |
1312 | 1330 | async def test_multiproject_async_context_propagation_basic(): |
@@ -1374,6 +1392,9 @@ async def async_level_1_function(*args, **kwargs): |
1374 | 1392 | ] |
1375 | 1393 | assert all(async_flags) |
1376 | 1394 |
|
| 1395 | + # Reset instances to not leak to other test suites |
| 1396 | + removeMockResourceManagerInstances() |
| 1397 | + |
1377 | 1398 |
|
1378 | 1399 | @pytest.mark.asyncio |
1379 | 1400 | async def test_multiproject_mixed_sync_async_context_propagation(): |
@@ -1443,6 +1464,9 @@ async def async_level_1_function(*args, **kwargs): |
1443 | 1464 | assert "sync" in types |
1444 | 1465 | assert "async" in types |
1445 | 1466 |
|
| 1467 | + # Reset instances to not leak to other test suites |
| 1468 | + removeMockResourceManagerInstances() |
| 1469 | + |
1446 | 1470 |
|
1447 | 1471 | @pytest.mark.asyncio |
1448 | 1472 | async def test_multiproject_concurrent_async_context_isolation(): |
@@ -1531,6 +1555,9 @@ async def async_level_1_function(task_id, *args, **kwargs): |
1531 | 1555 | assert "async_level_2_function" in trace_2_names |
1532 | 1556 | assert "async_level_3_function" in trace_2_names |
1533 | 1557 |
|
| 1558 | + # Reset instances to not leak to other test suites |
| 1559 | + removeMockResourceManagerInstances() |
| 1560 | + |
1534 | 1561 |
|
1535 | 1562 | @pytest.mark.asyncio |
1536 | 1563 | async def test_multiproject_async_generator_context_propagation(): |
@@ -1593,6 +1620,9 @@ async def async_consumer_function(): |
1593 | 1620 | # This confirms that the async generator inherited the public key context |
1594 | 1621 | assert len(trace_data.observations) == 2 |
1595 | 1622 |
|
| 1623 | + # Reset instances to not leak to other test suites |
| 1624 | + removeMockResourceManagerInstances() |
| 1625 | + |
1596 | 1626 |
|
1597 | 1627 | @pytest.mark.asyncio |
1598 | 1628 | async def test_multiproject_async_context_exception_handling(): |
@@ -1658,4 +1688,5 @@ async def async_root_function(*args, **kwargs): |
1658 | 1688 | ) |
1659 | 1689 | assert caught_obs is not None |
1660 | 1690 |
|
1661 | | - LangfuseResourceManager.reset() |
| 1691 | + # Reset instances to not leak to other test suites |
| 1692 | + removeMockResourceManagerInstances() |
0 commit comments