Skip to content

Commit 9ac9f41

Browse files
authored
Stop using event_loop fixture (#2969) (#2977)
It was removed in pytest-asyncio 1.0. (cherry picked from commit 3c9680a) # Conflicts: # docs/reference/async.md
1 parent 21757ef commit 9ac9f41

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

docs/sphinx/async.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ and are used in the same way as other APIs, just with an extra ``await``:
3737
)
3838
print(resp)
3939
40-
loop = asyncio.get_event_loop()
41-
loop.run_until_complete(main())
40+
asyncio.run(main())
4241
4342
All APIs that are available under the sync client are also available under the async client.
4443

@@ -153,8 +152,7 @@ Bulk and Streaming Bulk
153152
async def main():
154153
await async_bulk(client, gendata())
155154
156-
loop = asyncio.get_event_loop()
157-
loop.run_until_complete(main())
155+
asyncio.run(main())
158156
159157
.. autofunction:: async_streaming_bulk
160158

@@ -180,8 +178,7 @@ Bulk and Streaming Bulk
180178
if not ok:
181179
print("failed to %s document %s" % ())
182180
183-
loop = asyncio.get_event_loop()
184-
loop.run_until_complete(main())
181+
asyncio.run(main())
185182
186183
Scan
187184
~~~~
@@ -204,8 +201,7 @@ Scan
204201
):
205202
print(doc)
206203
207-
loop = asyncio.get_event_loop()
208-
loop.run_until_complete(main())
204+
asyncio.run(main())
209205
210206
Reindex
211207
~~~~~~~

test_elasticsearch/test_async/test_transport.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ async def test_sniff_on_node_failure_triggers(self, extra_key, extra_value):
527527
assert request_failed_in_error
528528
assert len(client.transport.node_pool) == 3
529529

530-
async def test_sniff_after_n_seconds(self, event_loop):
530+
async def test_sniff_after_n_seconds(self):
531+
event_loop = asyncio.get_running_loop()
531532
client = AsyncElasticsearch( # noqa: F821
532533
[NodeConfig("http", "localhost", 9200, _extras={"data": CLUSTER_NODES})],
533534
node_class=DummyNode,
@@ -581,7 +582,8 @@ async def test_sniffing_disabled_on_elastic_cloud(self, kwargs):
581582
== "Sniffing should not be enabled when connecting to Elastic Cloud"
582583
)
583584

584-
async def test_sniff_on_start_close_unlocks_async_calls(self, event_loop):
585+
async def test_sniff_on_start_close_unlocks_async_calls(self):
586+
event_loop = asyncio.get_running_loop()
585587
client = AsyncElasticsearch( # noqa: F821
586588
[
587589
NodeConfig(

0 commit comments

Comments
 (0)