Skip to content
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

Prevent an uncaught exception warning in a test suite thread #635

Merged

Conversation

kurtmckee
Copy link
Contributor

Spotted this while attempting to run the test suite locally with warnings enabled:

tests/middleware/test_asyncio.py::test_event_loop_thread_start_timeout
  lib/python3.12/site-packages/_pytest/threadexception.py:77:
    PytestUnhandledThreadExceptionWarning: Exception in thread Thread-13

The easiest fix is to stop raising an exception in the mock. In addition, since RuntimeError may be raised in several ways, I added a match argument to the pytest.raises() context manager to identify which RuntimeError text is expected.

After avoiding that warning, a ResourceWarning popped up:

tests/middleware/test_asyncio.py::test_event_loop_thread_start_timeout
  lib/python3.12/asyncio/base_events.py:726:
    ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>

This happens because the underlying event loop (the one that is getting swapped out with a mock) is not getting closed.

After avoiding that warning, a ResourceWarning must be caught
due to an underlying event loop not getting closed.
@Bogdanp Bogdanp merged commit a7f83db into Bogdanp:master Jun 25, 2024
11 checks passed
@kurtmckee kurtmckee deleted the prevent-uncaught-thread-exception-warning branch June 25, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants