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

Following quickstart causes noisy errors on setUp #10

Open
RomHartmann opened this issue May 9, 2019 · 0 comments
Open

Following quickstart causes noisy errors on setUp #10

RomHartmann opened this issue May 9, 2019 · 0 comments

Comments

@RomHartmann
Copy link

First of all, thank you for wonderful work.

Following the quickstart at https://pypi.org/project/testing.mysqld/, I would get this very noisy error message:

.{base.py:680} ERROR - Exception during reset or similar
Traceback (most recent call last):
  File "/Users/romanhartmann/.virtualenvs/ub-data-product/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 671, in _finalize_fairy
    fairy._reset(pool)
  File "/Users/romanhartmann/.virtualenvs/ub-data-product/lib/python3.6/site-packages/sqlalchemy/pool/base.py", line 858, in _reset
    pool._dialect.do_rollback(self)
  File "/Users/romanhartmann/.virtualenvs/ub-data-product/lib/python3.6/site-packages/sqlalchemy/dialects/mysql/base.py", line 2227, in do_rollback
    dbapi_connection.rollback()
  File "/Users/romanhartmann/.virtualenvs/ub-data-product/lib/python3.6/site-packages/pymysql/connections.py", line 430, in rollback
    self._read_ok_packet()
  File "/Users/romanhartmann/.virtualenvs/ub-data-product/lib/python3.6/site-packages/pymysql/connections.py", line 394, in _read_ok_packet
    pkt = self._read_packet()
  File "/Users/romanhartmann/.virtualenvs/ub-data-product/lib/python3.6/site-packages/pymysql/connections.py", line 657, in _read_packet
    packet_header = self._read_bytes(4)
  File "/Users/romanhartmann/.virtualenvs/ub-data-product/lib/python3.6/site-packages/pymysql/connections.py", line 707, in _read_bytes
    CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")
pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query')

My unit test setup was like this:

class TestWhatever(unittest.TestCase):

    def setUp(self):
        self.mysql = testing.mysqld.Mysqld(port=7531)
        self.target_conn = create_engine(self.mysql.url()).connect()
        self.target_conn.execute("""CREATE TABLE `foo` (blah)""")

    def tearDown(self):
        self.target_conn.execute("DROP TABLE foo")
        self.mysql.stop()

    def test_something(self):
        # something useful

This error did not cause any tests to fail, it was just being logged all the time.
I was using the exact same setup for testing.postgresql without the error.

I changed my test class to this to get rid of the error:

MYSQLD_FACTORY = testing.mysqld.MysqldFactory(cache_initialized_db=True, port=7531)


def tearDownModule():
    """Tear down databases after test script has run.

    https://docs.python.org/3/library/unittest.html#setupclass-and-teardownclass
    """
    MYSQLD_FACTORY.clear_cache()


class TestWhatever(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.mysql = MYSQLD_FACTORY()
        cls.target_conn = create_engine(cls.mysql.url()).connect()

    def setUp(self):
        self.mysql.start()
        self.target_conn.execute("""CREATE TABLE `foo` (blah)""")

    def tearDown(self):
        self.target_conn.execute("DROP TABLE foo")

    @classmethod
    def tearDownClass(cls):
        cls.mysql.stop()

    def test_something(self):
        # something useful

Would you please update your documentation to either

  • Outline what I did wrong to prevent other people having to figure this out. I've seen a lot of SO posts about the vague pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query') error in relation to this package
  • Document this pattern as a working pattern
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

No branches or pull requests

1 participant