dstromberg
dstromberg

Reputation: 7177

coverage.py's SQLite use seems to break my test suite, which also uses SQLite

I'm porting some code from python2 to python3. Part of that is seeing how much our Flask-based REST API is covered by our automated tests, and deciding where, if anywhere, manual testing is needed.

In case it matters, we are using "with app.test_client() as client" heavily in the tests. I don't think the test suite hits the REST API over http or https.

Because I need python2 support for now, I'm stuck with coverage.py 5.5 or earlier for now.

The automated tests for this project use pytest and SQLite. They run fine in the absence of coverage.py.

However, as soon as I run the test suite with coverage.py enabled, I start getting lots of SQLite IntegrityError's from the test suite. Here's an example invocation of pytest with coverage.py:

/usr/bin/python2 ~/.local/bin/coverage run -m pytest

Here are some example errors:

E IntegrityError: (pysqlite2.dbapi2.IntegrityError) UNIQUE constraint failed: users.username [SQL: u'INSERT INTO users (username, btag, first_name, last_name, region, created_on, updated_on, deleted_on) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('admin-user', None, None, None, None, '2022-07-20 23:01:33.993285', '2022-07-20 23:01:33.993290', None)] (Background on this error at: http://sqlalche.me/e/gkpj)
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py:507: IntegrityError
E IntegrityError: (pysqlite2.dbapi2.IntegrityError) UNIQUE constraint failed: users.username [SQL: u'INSERT INTO users (username, btag, first_name, last_name, region, created_on, updated_on, deleted_on) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('admin-user', None, None, None, None, '2022-07-20 23:01:34.555887', '2022-07-20 23:01:34.555894', None)] (Background on this error at: http://sqlalche.me/e/gkpj)
/usr/local/lib/python2.7/dist-packages/sqlalchemy/engine/default.py:507: IntegrityError
E IntegrityError: (pysqlite2.dbapi2.IntegrityError) UNIQUE constraint failed: users.username [SQL: u'INSERT INTO users (username, btag, first_name, last_name, region, created_on, updated_on, deleted_on) VALUES (?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('admin-user', None, None, None, None, '2022-07-20 23:01:34.979448', '2022-07-20 23:01:34.979454', None)] (Background on this error at: http://sqlalche.me/e/gkpj)

I half-suspect that coverage.py is setting some sort of SQLite configuration option that is breaking our tests.

Questions:

  1. Does it sound likely that my test suite is conflicting with coverage.py due to them using SQLite in a conflicting way?
  2. Is there a way to make coverage.py use some other sort of database?
  3. What other explanations might there be?

Thanks!

Update: I just tried coverage==4.5.4 and "coverage run -m pytest", but still got many similar SQLite IntegrityError's. coverage.py 4.5.4 uses JSON, not SQLite, I believe.

Upvotes: 0

Views: 599

Answers (1)

dstromberg
dstromberg

Reputation: 7177

The test suite is fine, and coverage.py is fine. It turned out to be an environment variable difference.

Upvotes: 0

Related Questions