Coverage for tests / test_param_cancellable.py: 100%

25 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-05-05 09:41 +0000

1import warnings 1opqrstu

2 

3import anyio 1opqrstu

4import pytest 1opqrstu

5from asyncer import asyncify 1opqrstu

6 

7 

8def test_cancellable_warns(): 1opqrstu

9 def do_async_work(): 1abcdefg

10 return "Hello World!" 1abcdefg

11 

12 async def main(): 1abcdefg

13 result = await asyncify(do_async_work, cancellable=True)() 1abcdefg

14 return result 1abcdefg

15 

16 with pytest.warns(DeprecationWarning) as record: 1abcdefg

17 result = anyio.run(main) 1abcdefg

18 assert isinstance(record[0].message, Warning) 1abcdefg

19 assert ( 1abcdefg

20 "The `cancellable=` keyword argument to `asyncer.asyncify()` is " 

21 "deprecated since Asyncer 0.0.8" in record[0].message.args[0] 

22 ) 

23 assert result == "Hello World!" 1abcdefg

24 

25 

26def test_abandon_on_cancel_no(): 1opqrstu

27 def do_async_work(): 1hijklmn

28 return "Hello World!" 1hijklmn

29 

30 async def main(): 1hijklmn

31 result = await asyncify(do_async_work, abandon_on_cancel=True)() 1hijklmn

32 return result 1hijklmn

33 

34 with warnings.catch_warnings(): 1hijklmn

35 warnings.simplefilter("error") 1hijklmn

36 result = anyio.run(main) 1hijklmn

37 assert result == "Hello World!" 1hijklmn