@@ -679,7 +679,11 @@ def test_prompt_end_to_end():
679679
680680@pytest .fixture
681681def langfuse ():
682- langfuse_instance = Langfuse ()
682+ langfuse_instance = Langfuse (
683+ public_key = "test-public-key" ,
684+ secret_key = "test-secret-key" ,
685+ host = "https://mock-host.com" ,
686+ )
683687 langfuse_instance .api = Mock ()
684688
685689 return langfuse_instance
@@ -1410,3 +1414,50 @@ def test_update_prompt():
14101414 expected_labels = sorted (["latest" , "doe" , "production" , "john" ])
14111415 assert sorted (fetched_prompt .labels ) == expected_labels
14121416 assert sorted (updated_prompt .labels ) == expected_labels
1417+
1418+
1419+ def test_clear_prompt_cache (langfuse ):
1420+ """Test clearing the entire prompt cache."""
1421+ prompt_name = create_uuid ()
1422+
1423+ # Mock the API calls
1424+ mock_prompt = Prompt_Text (
1425+ name = prompt_name ,
1426+ version = 1 ,
1427+ prompt = "test prompt" ,
1428+ type = "text" ,
1429+ labels = ["production" ],
1430+ config = {},
1431+ tags = [],
1432+ )
1433+
1434+ # Mock the create_prompt API call
1435+ langfuse .api .prompts .create .return_value = mock_prompt
1436+
1437+ # Mock the get_prompt API call
1438+ langfuse .api .prompts .get .return_value = mock_prompt
1439+
1440+ # Create a prompt and cache it
1441+ prompt_client = langfuse .create_prompt (
1442+ name = prompt_name ,
1443+ prompt = "test prompt" ,
1444+ labels = ["production" ],
1445+ )
1446+
1447+ # Get the prompt to cache it
1448+ cached_prompt = langfuse .get_prompt (prompt_name )
1449+ assert cached_prompt .name == prompt_name
1450+
1451+ # Verify that the prompt is in the cache
1452+ cache_key = f"{ prompt_name } -label:production"
1453+ assert langfuse ._resources .prompt_cache .get (cache_key ) is not None , "Prompt should be in cache before clearing"
1454+
1455+ # Clear the entire prompt cache
1456+ langfuse .clear_prompt_cache ()
1457+
1458+ # Verify cache is completely cleared
1459+ assert langfuse ._resources .prompt_cache .get (cache_key ) is None , "Prompt should be removed from cache after clearing"
1460+
1461+ # Verify data integrity
1462+ assert prompt_client .name == prompt_name
1463+ assert cached_prompt .name == prompt_name
0 commit comments