Skip to content

Commit

Permalink
Avoid warning when running FreezeGun tests on Python 3.10+
Browse files Browse the repository at this point in the history
To avoid this warning:

    freezegun/tests/test_asyncio.py:12: DeprecationWarning: There is no current event loop
      asyncio.get_event_loop().run_until_complete(frozen_coroutine())

on Python 3.10+, we modify tests to use `asyncio.run` instead of
`asyncio.get_event_loop().run_until_complete`, which [1] recommends:

    asyncio.get_event_loop()
      (...)
      Consider also using the asyncio.run() function instead of using
      lower level functions to manually create and close an event loop.

      Deprecated since version 3.10: Deprecation warning is emitted
      if there is no running event loop. In future Python releases,
      this function will be an alias of get_running_loop().

`asyncio.run` has been added in Python 3.7 but we no longer support 3.6
(see spulec#455) so we can use it.

[1] https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.get_event_loop
  • Loading branch information
marcinsulikowski committed Sep 14, 2022
1 parent fc84ad0 commit 86f69e4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ def test_datetime_in_coroutine():
async def frozen_coroutine():
assert datetime.date.today() == datetime.date(1970, 1, 1)

asyncio.get_event_loop().run_until_complete(frozen_coroutine())
asyncio.run(frozen_coroutine())

0 comments on commit 86f69e4

Please sign in to comment.