pulumi / pulumi

Pulumi - Infrastructure as Code in any programming language šŸš€
https://www.pulumi.com
Apache License 2.0
20.96k stars 1.09k forks source link

Remove usage of `ensure_future` in Python SDK #11827

Open jaxxstorm opened 1 year ago

jaxxstorm commented 1 year ago

What happened?

When writing unit tests with pytest, there are lots of deprecation warnings:

test_website.py: 13 warnings
  /Users/lbriggs/src/github/jaxxstorm/pulumi-examples/python/azure/tested_static_website/venv/lib/python3.10/site-packages/pulumi/runtime/sync_await.py:94: DeprecationWarning: There is no current event loop
    loop = asyncio.get_event_loop()

This seems related to the usage asyncio.ensure_future which is deprecated:

https://docs.python.org/3/library/asyncio-future.html#asyncio.ensure_future

Steps to reproduce

Write a standard unit test for a python component run pytest

Expected Behavior

Only errors related to the test are thrown

Actual Behavior

You get a whole load of deprecation warnings

Output of pulumi about

No response

Additional context

You can suppress this by doing python -m pytest --disable-pytest-warnings but we should still remove use of a deprecated method

Contributing

Vote on this issue by adding a šŸ‘ reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

RobbieMcKinstry commented 1 year ago

I'm curious to take a look at how pervasive the use of ensure_future is. From reading the docs:

Deprecated since version 3.10: Deprecation warning is emitted if obj is not a Future-like object and loop is not specified and there is no running event loop.

It sounds like ensure_future isn't totally deprecated, but only if you're not using it as intended. That's how I'm reading it, at least.