Skip to content

Commit 72dcbf9

Browse files
committed
Use fixture event_loop instead of the deprecated fixture loop
Fixes DeprecationWarning: 'loop' fixture is deprecated and scheduled for removal, please use 'event_loop' instead Except for `ext-aiohttp` because `pytest-aiohttp < 1.0.0` is too old for that.
1 parent 6e30483 commit 72dcbf9

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

tests/ext/aiobotocore/test_aiobotocore.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212

1313

1414
@pytest.fixture(scope='function')
15-
def recorder(loop):
15+
def recorder(event_loop):
1616
"""
1717
Clean up before and after each test run
1818
"""
19-
xray_recorder.configure(service='test', sampling=False, context=AsyncContext(loop=loop))
19+
xray_recorder.configure(
20+
service='test', sampling=False, context=AsyncContext(loop=event_loop)
21+
)
2022
xray_recorder.clear_trace_entities()
2123
yield xray_recorder
2224
xray_recorder.clear_trace_entities()
2325

2426

25-
async def test_describe_table(loop, recorder):
27+
async def test_describe_table(event_loop, recorder):
2628
segment = recorder.begin_segment('name')
2729

2830
req_id = '1234'
@@ -45,7 +47,7 @@ async def test_describe_table(loop, recorder):
4547
assert aws_meta['operation'] == 'DescribeTable'
4648

4749

48-
async def test_s3_parameter_capture(loop, recorder):
50+
async def test_s3_parameter_capture(event_loop, recorder):
4951
segment = recorder.begin_segment('name')
5052

5153
bucket_name = 'mybucket'
@@ -70,7 +72,7 @@ async def test_s3_parameter_capture(loop, recorder):
7072
assert aws_meta['operation'] == 'GetObject'
7173

7274

73-
async def test_list_parameter_counting(loop, recorder):
75+
async def test_list_parameter_counting(event_loop, recorder):
7476
"""
7577
Test special parameters that have shape of list are recorded
7678
as count based on `para_whitelist.json`
@@ -103,7 +105,7 @@ async def test_list_parameter_counting(loop, recorder):
103105
assert aws_meta['queue_name_prefix'] == queue_name_prefix
104106

105107

106-
async def test_map_parameter_grouping(loop, recorder):
108+
async def test_map_parameter_grouping(event_loop, recorder):
107109
"""
108110
Test special parameters that have shape of map are recorded
109111
as a list of keys based on `para_whitelist.json`
@@ -131,9 +133,10 @@ async def test_map_parameter_grouping(loop, recorder):
131133
assert sorted(aws_meta['table_names']) == ['table1', 'table2']
132134

133135

134-
async def test_context_missing_not_swallow_return(loop, recorder):
136+
async def test_context_missing_not_swallow_return(event_loop, recorder):
135137
xray_recorder.configure(service='test', sampling=False,
136-
context=AsyncContext(loop=loop), context_missing='LOG_ERROR')
138+
context=AsyncContext(loop=event_loop),
139+
context_missing='LOG_ERROR')
137140

138141
response = {'ResponseMetadata': {'RequestId': '1234', 'HTTPStatusCode': 403}}
139142

@@ -146,9 +149,10 @@ async def test_context_missing_not_swallow_return(loop, recorder):
146149
assert actual_resp == response
147150

148151

149-
async def test_context_missing_not_suppress_exception(loop, recorder):
152+
async def test_context_missing_not_suppress_exception(event_loop, recorder):
150153
xray_recorder.configure(service='test', sampling=False,
151-
context=AsyncContext(loop=loop), context_missing='LOG_ERROR')
154+
context=AsyncContext(loop=event_loop),
155+
context_missing='LOG_ERROR')
152156

153157
session = get_session()
154158
async with session.create_client('dynamodb', region_name='eu-west-2') as client:

tests/test_async_local_storage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from aws_xray_sdk.core.async_context import TaskLocalStorage
55

66

7-
def test_localstorage_isolation(loop):
8-
local_storage = TaskLocalStorage(loop=loop)
7+
def test_localstorage_isolation(event_loop):
8+
local_storage = TaskLocalStorage(loop=event_loop)
99

1010
async def _test():
1111
"""
@@ -19,7 +19,7 @@ async def _test():
1919
random_int = random.random()
2020
local_storage.randint = random_int
2121

22-
await asyncio.sleep(0.0, loop=loop)
22+
await asyncio.sleep(0.0, loop=event_loop)
2323

2424
current_random_int = local_storage.randint
2525
assert random_int == current_random_int
@@ -29,8 +29,8 @@ async def _test():
2929
return False
3030

3131
# Run loads of concurrent tasks
32-
results = loop.run_until_complete(
33-
asyncio.wait([_test() for _ in range(0, 100)], loop=loop)
32+
results = event_loop.run_until_complete(
33+
asyncio.wait([_test() for _ in range(0, 100)], loop=event_loop)
3434
)
3535
results = [item.result() for item in results[0]]
3636

tests/test_async_recorder.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ async def async_method():
1919
await async_method2()
2020

2121

22-
async def test_capture(loop):
23-
xray_recorder.configure(service='test', sampling=False, context=AsyncContext(loop=loop))
22+
async def test_capture(event_loop):
23+
xray_recorder.configure(
24+
service='test', sampling=False, context=AsyncContext(loop=event_loop)
25+
)
2426

2527
segment = xray_recorder.begin_segment('name')
2628

@@ -44,8 +46,10 @@ async def test_capture(loop):
4446
assert platform.python_implementation() == service.get('runtime')
4547
assert platform.python_version() == service.get('runtime_version')
4648

47-
async def test_concurrent_calls(loop):
48-
xray_recorder.configure(service='test', sampling=False, context=AsyncContext(loop=loop))
49+
async def test_concurrent_calls(event_loop):
50+
xray_recorder.configure(
51+
service='test', sampling=False, context=AsyncContext(loop=event_loop)
52+
)
4953
async with xray_recorder.in_segment_async('segment') as segment:
5054
global counter
5155
counter = 0
@@ -67,8 +71,10 @@ async def assert_task():
6771
assert subseg_parent_id == segment.id
6872

6973

70-
async def test_async_context_managers(loop):
71-
xray_recorder.configure(service='test', sampling=False, context=AsyncContext(loop=loop))
74+
async def test_async_context_managers(event_loop):
75+
xray_recorder.configure(
76+
service='test', sampling=False, context=AsyncContext(loop=event_loop)
77+
)
7278

7379
async with xray_recorder.in_segment_async('segment') as segment:
7480
async with xray_recorder.capture_async('aio_capture') as subsegment:

tox.ini

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ deps =
6868
py34: typing >= 3.7.4.3
6969

7070
; Python 3.5+ only deps
71-
; for some reason pytest-aiohttp is required for "core" tests
72-
; TODO: find and replace by more direct dependency
73-
py{35,36,37,38,39}: pytest-aiohttp
71+
py{35,36,37,38,39}: pytest-asyncio
7472

7573
ext-aiobotocore: aiobotocore >= 0.10.0
76-
ext-aiobotocore: pytest-aiohttp
74+
ext-aiobotocore: pytest-asyncio
7775

7876
ext-aiohttp: aiohttp >= 3.0.0
7977
; Breaking change where the `test_client` fixture was renamed.

0 commit comments

Comments
 (0)