-
Notifications
You must be signed in to change notification settings - Fork 159
Use a loop proxy for better flexibility #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This sounds interesting! As you mentioned in another comment the loop proxy could address many things related to loop teardown and orphaned tasks, because the context manager takes care of this when it exits. aioloop-proxy also includes an I played around with aioloop-proxy a bit. A large number of tests already work when replacing a couple of lines in
The failing tests were mostly related to subprocesses or setting a custom event loop or policy. Some special usage like the one in TestEventLoopStartedBeforeFixtures break, because the tasks in the test cases get attached to a different loop. Anyway, the new information made me wonder if the That's all I got for now :) |
From my point of view, the plugin should support two modes.
An overridable session-scope fixture exists that returns a root loop instance. An user can override this fixture in Each pytest node should have a loop proxy instance created from the proxy of the parent loop. |
Issue #91 is yet another problem that caused by the @asvetlov @Tinche Would it make sense to clean up open tasks before closing the current loop? This could serve as an intermediate solution until we integrate |
Good question! |
any update on this, is there any way to shut down tasks at the end before exit? getting a lot of these errors: [gw7] [100%] PASSED test.py::SomeTestClass::test_playwright_event_loop_cleanup Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x107244900>
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.12.10/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_subprocess.py", line 126, in __del__
self.close()
File "/opt/homebrew/Cellar/[email protected]/3.12.10/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_subprocess.py", line 104, in close
proto.pipe.close()
File "/opt/homebrew/Cellar/[email protected]/3.12.10/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/unix_events.py", line 568, in close
self._close(None)
File "/opt/homebrew/Cellar/[email protected]/3.12.10/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/unix_events.py", line 592, in _close
self._loop.call_soon(self._call_connection_lost, exc)
File "/opt/homebrew/Cellar/[email protected]/3.12.10/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 799, in call_soon
self._check_closed()
File "/opt/homebrew/Cellar/[email protected]/3.12.10/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 545, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Task was destroyed but it is pending!
task: <Task pending name='Task-44' coro=<Connection.run() running at /app/.venv/lib/python3.12/site-packages/playwright/_impl/_connection.py:281> wait_for=<Future pending cb=[Task.task_wakeup()]>> |
aioloop-proxy provide a proxy instance that is fully compatible with
asyncio.AbstractEventLoop
but allows to cooperate of multiple nested proxies at the same time.From pytest-asyncio point of view, a session-scope fixture can use a session-level loop proxy that can cooperate with module-level, class-level, and function-level ones providing good test isolation.
I have no proof of concept for pytest-asyncio yet, if somebody with deep pytest internals knowledge can help -- you are welcome!
The text was updated successfully, but these errors were encountered: