From 82217d23d4a175760e573805bbc45a8cb110efcd Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Tue, 24 Dec 2024 22:37:18 -0600 Subject: [PATCH] correctly name file --- .../results/{storage.py => test_storage.py} | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) rename tests/public/results/{storage.py => test_storage.py} (52%) diff --git a/tests/public/results/storage.py b/tests/public/results/test_storage.py similarity index 52% rename from tests/public/results/storage.py rename to tests/public/results/test_storage.py index 134449fc9215..67896b2b9c61 100644 --- a/tests/public/results/storage.py +++ b/tests/public/results/test_storage.py @@ -1,4 +1,5 @@ from pathlib import Path +from unittest.mock import patch import anyio import pytest @@ -34,17 +35,25 @@ async def awrite_path(self, path: str, content: bytes) -> str: async def test_async_method_used_in_async_context( custom_storage_block: LocalFileSystem, ): - @task(result_storage=custom_storage_block, result_storage_key="testing") - async def t(): - return "this is a test" - - @flow - async def f(): - return await t() - - result = await f() - assert result == "this is a test" - store = ResultStore(result_storage=custom_storage_block) - stored_result_record = await store.aread("testing") - - assert stored_result_record.result == result == "this is a test" + # this is a regression test for https://github.com/PrefectHQ/prefect/issues/16486 + with patch.object( + custom_storage_block, "awrite_path", wraps=custom_storage_block.awrite_path + ) as mock_awrite: + + @task(result_storage=custom_storage_block, result_storage_key="testing") + async def t(): + return "this is a test" + + @flow + async def f(): + return await t() + + result = await f() + assert result == "this is a test" + store = ResultStore(result_storage=custom_storage_block) + stored_result_record = await store.aread("testing") + + assert stored_result_record.result == result == "this is a test" + # Verify awrite_path was called + mock_awrite.assert_awaited_once() + assert mock_awrite.await_args[0][0] == "testing" # Check path argument