-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
78 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,23 @@ | ||
from prefect import flow, task | ||
|
||
import pytest | ||
|
||
async def test_awaiting_formerly_async_methods(): | ||
import warnings | ||
from prefect import flow, task | ||
|
||
N = 5 | ||
|
||
@pytest.mark.parametrize( | ||
"method,args", | ||
[ | ||
("submit", (None,)), | ||
("map", ([None],)), | ||
], | ||
) | ||
async def test_awaiting_previously_async_task_methods_fail(method, args): | ||
@task | ||
def get_random_number(_) -> int: | ||
async def get_random_number(_) -> int: | ||
return 42 | ||
|
||
@flow | ||
async def get_some_numbers_old_await_syntax(): | ||
state1 = await get_random_number.submit(None, return_state=True) | ||
assert state1.is_completed() | ||
|
||
future1 = await get_random_number.submit(None) | ||
|
||
await future1.wait() | ||
assert await future1.result() == 42 | ||
|
||
list_of_futures = await get_random_number.map([None] * N) | ||
[await future.wait() for future in list_of_futures] | ||
assert all([await future.result() == 42 for future in list_of_futures]) | ||
|
||
@flow | ||
async def get_some_numbers_new_way(): | ||
state1 = get_random_number.submit(None, return_state=True) | ||
assert state1.is_completed() | ||
|
||
future1 = get_random_number.submit(None) | ||
future1.wait() | ||
assert future1.result() == 42 | ||
|
||
list_of_futures = get_random_number.map([None] * N) | ||
[future.wait() for future in list_of_futures] | ||
assert all(future.result() == 42 for future in list_of_futures) | ||
|
||
# Test the old way (with await) | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
await get_some_numbers_old_await_syntax() | ||
deprecation_warnings = [ | ||
_w for _w in w if issubclass(_w.category, DeprecationWarning) | ||
] | ||
|
||
assert all( | ||
"please remove the `await` keyword" in str(warning.message) | ||
for warning in deprecation_warnings | ||
) | ||
async def run_a_task(): | ||
await getattr(get_random_number, method)(*args) | ||
|
||
# Test the new way (without await) | ||
with warnings.catch_warnings(record=True) as w: | ||
warnings.simplefilter("always") | ||
await get_some_numbers_new_way() | ||
deprecation_warnings = [ | ||
_w for _w in w if issubclass(_w.category, DeprecationWarning) | ||
] | ||
assert len(deprecation_warnings) == 0 | ||
with pytest.raises(TypeError, match="can't be used in 'await' expression"): | ||
await run_a_task() |