pymysql.err.InterfaceError: (0, '') during bench run-tests

I tried bench run-tests --app frappe. Tons of error occured, most of which are of the same type like this:

======================================================================
ERROR: setUpClass (frappe.tests.test_linked_with.TestLinkedWith)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/frapper/erpnext/apps/frappe/frappe/tests/utils.py", line 27, in setUpClass
    frappe.db.commit()
  File "/home/frapper/erpnext/apps/frappe/frappe/database/database.py", line 968, in commit
    self.sql("commit")
  File "/home/frapper/erpnext/apps/frappe/frappe/database/database.py", line 209, in sql
    self._cursor.execute(query, values)
  File "/home/frapper/erpnext/env/lib/python3.10/site-packages/pymysql/cursors.py", line 148, in execute
    result = self._query(query)
  File "/home/frapper/erpnext/env/lib/python3.10/site-packages/pymysql/cursors.py", line 310, in _query
    conn.query(q)
  File "/home/frapper/erpnext/env/lib/python3.10/site-packages/pymysql/connections.py", line 547, in query
    self._execute_command(COMMAND.COM_QUERY, sql)
  File "/home/frapper/erpnext/env/lib/python3.10/site-packages/pymysql/connections.py", line 793, in _execute_command
    raise err.InterfaceError(0, "")
pymysql.err.InterfaceError: (0, '')

Here is the relevant connections.py code:

   def _execute_command(self, command, sql):
        """
        :raise InterfaceError: If the connection is closed.
        :raise ValueError: If no username was specified.
        """
        if not self._sock:
            raise err.InterfaceError(0, "")

The db server works fine, why does it fail to be connected during testing? Is it due to too many connections?

This usually happens when DB drops the connection unexpectedly which can happen from many reasons. Maybe run one test at a time instead of all? (No use of running all tests outside of continuous integration systems)

Too many connections surely isn’t a reason for this, cause test runner maintains the same connection throughout all tests (with some minor exceptions)

Thanks for the info. I’ll run the tests in problem one by one, but I wonder running all the tests at least in the current worked module is not the routine job in the building process? (I used to dev in Java and maven would run all the tests in normal building to ensure nothing breaks)