s3rius / FastAPI-template

Feature rich robust FastAPI template.
MIT License
1.94k stars 168 forks source link

RuntimeError After Pytest Completion #197

Open siwonKH opened 10 months ago

siwonKH commented 10 months ago

Issue

Encountering a RuntimeError: Event loop is closed error when running pytest in a Docker environment. This issue arises even though the tests complete successfully.

Environment

Error Observed

template_test/tests/test_dummy.py::test_creation PASSED
template_test/tests/test_dummy.py::test_getting PASSED
template_test/tests/test_echo.py::test_echo PASSED
template_test/tests/test_template_test.py::test_health PASSED

======================================================================================================== 4 passed in 5.37s =========================================================================================================
Exception ignored in: <function Connection.__del__ at 0x7f626e7e3a60>
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiomysql/connection.py", line 1131, in __del__
    self.close()
  File "/usr/local/lib/python3.11/site-packages/aiomysql/connection.py", line 339, in close
    self._writer.transport.close()
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 860, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 761, in call_soon
    self._check_closed()
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 519, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function Connection.__del__ at 0x7f626e7e3a60>
Traceback (most recent call last):
    self.close()
  File "/usr/local/lib/python3.11/site-packages/aiomysql/connection.py", line 339, in close
    self._writer.transport.close()
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 860, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 761, in call_soon
    self._check_closed()
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

This RuntimeError is logged after the successful completion of tests.

Attempted Fix