tests/tests_core/test_api_test.py often hangs during test cleanup #10

Closed
opened 2023-03-18 12:38:50 +00:00 by missytake · 4 comments
Owner

Expected Behavior

pytest quits after successfully running the tests.

Actual Behavior

After printing 6 passed, 1 warning, pytest stalls and never returns. ctrl+c shows that a thread can't shutdown because it never gets a lock.

pytest tests/tests_core/test_api_test.py
============================================================================================================ test session starts ============================================================================================================
platform linux -- Python 3.10.6, pytest-7.2.2, pluggy-1.0.0
rootdir: /home/user/git/ticketfrei3
plugins: asyncio-0.20.3, anyio-3.6.2, aiohttp-1.0.4
asyncio: mode=strict
collected 6 items                                                                                                                                                                                                                           

tests/tests_core/test_api_test.py ......                                                                                                                                                                                              [100%]

============================================================================================================= warnings summary ==============================================================================================================
tests/tests_core/test_api_test.py::test_test_read_all_unauthorized
  /home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/ormantic/models.py:64: RemovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
    expr = sqlalchemy.sql.select(functions or tables)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================================================================= 6 passed, 1 warning in 3.20s ========================================================================================================
^CException ignored in: <module 'threading' from '/usr/lib/python3.10/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1567, in _shutdown
    lock.acquire()
KeyboardInterrupt: 
## Expected Behavior `pytest` quits after successfully running the tests. ## Actual Behavior After printing `6 passed, 1 warning`, pytest stalls and never returns. ctrl+c shows that a thread can't shutdown because it never gets a lock. ``` pytest tests/tests_core/test_api_test.py ============================================================================================================ test session starts ============================================================================================================ platform linux -- Python 3.10.6, pytest-7.2.2, pluggy-1.0.0 rootdir: /home/user/git/ticketfrei3 plugins: asyncio-0.20.3, anyio-3.6.2, aiohttp-1.0.4 asyncio: mode=strict collected 6 items tests/tests_core/test_api_test.py ...... [100%] ============================================================================================================= warnings summary ============================================================================================================== tests/tests_core/test_api_test.py::test_test_read_all_unauthorized /home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/ormantic/models.py:64: RemovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings. Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9) expr = sqlalchemy.sql.select(functions or tables) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ======================================================================================================= 6 passed, 1 warning in 3.20s ======================================================================================================== ^CException ignored in: <module 'threading' from '/usr/lib/python3.10/threading.py'> Traceback (most recent call last): File "/usr/lib/python3.10/threading.py", line 1567, in _shutdown lock.acquire() KeyboardInterrupt: ```
Author
Owner

The single tests usually quit successfully.

Sometimes (but not during every run) also this traceback appears:

tests/tests_core/test_api_test.py::test_test_message_create_unauthorized
  /home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-132
  
  Traceback (most recent call last):
    File "/home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/aiosqlite/core.py", line 117, in run
      get_loop(future).call_soon_threadsafe(set_result, future, result)
    File "/usr/lib/python3.10/asyncio/base_events.py", line 795, in call_soon_threadsafe
      self._check_closed()
    File "/usr/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed
      raise RuntimeError('Event loop is closed')
  RuntimeError: Event loop is closed
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
      self.run()
    File "/home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/aiosqlite/core.py", line 125, in run
      get_loop(future).call_soon_threadsafe(set_exception, future, e)
    File "/usr/lib/python3.10/asyncio/base_events.py", line 795, in call_soon_threadsafe
      self._check_closed()
    File "/usr/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed
      raise RuntimeError('Event loop is closed')
  RuntimeError: Event loop is closed
  
    warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))
The single tests usually quit successfully. Sometimes (but not during every run) also this traceback appears: ``` tests/tests_core/test_api_test.py::test_test_message_create_unauthorized /home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/_pytest/threadexception.py:73: PytestUnhandledThreadExceptionWarning: Exception in thread Thread-132 Traceback (most recent call last): File "/home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/aiosqlite/core.py", line 117, in run get_loop(future).call_soon_threadsafe(set_result, future, result) File "/usr/lib/python3.10/asyncio/base_events.py", line 795, in call_soon_threadsafe self._check_closed() File "/usr/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/home/user/git/ticketfrei3/.venv/lib/python3.10/site-packages/aiosqlite/core.py", line 125, in run get_loop(future).call_soon_threadsafe(set_exception, future, e) File "/usr/lib/python3.10/asyncio/base_events.py", line 795, in call_soon_threadsafe self._check_closed() File "/usr/lib/python3.10/asyncio/base_events.py", line 515, in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) ```
Author
Owner

Hm, sometimes it also works. Weeeeird

Hm, sometimes it also works. Weeeeird
missytake changed title from tests/tests_core/test_api_test.py never exits correctly to tests/tests_core/test_api_test.py often hangs during test cleanup 2023-03-18 13:47:55 +00:00
Author
Owner

If it hangs, the CPU is at 100%

If it hangs, the CPU is at 100%
Author
Owner

fixed in #9.

fixed in #9.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: ticketfrei/ticketfrei3#10
No description provided.