pytest-testmon: sqlite3.OperationalError: database is locked

Hi there! I’m looking into using pytest-testmon, but have bumped into this error a few times:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/_pytest/main.py", line 266, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1037, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/pluggy/_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/testmon/pytest_testmon.py", line 189, in pytest_configure
INTERNALERROR>     init_testmon_data(config)
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/testmon/pytest_testmon.py", line 126, in init_testmon_data
INTERNALERROR>     testmon_data = TestmonData(
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/testmon/testmon_core.py", line 139, in __init__
INTERNALERROR>     self.db = db.DB(self.datafile, self.environment)
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/testmon/db.py", line 49, in __init__
INTERNALERROR>     connection = connect(datafile)
INTERNALERROR>   File "/.venv/lib/python3.10/site-packages/testmon/db.py", line 38, in connect
INTERNALERROR>     connection.execute("PRAGMA synchronous = OFF")
INTERNALERROR> sqlite3.OperationalError: database is locked

I’m running watchdog pytest.main, which will sometimes send a SIGKILL to pytest if it’s taking too long, and I’m wondering whether this might create a broken state. The only way I’ve been able to successfully resolve this issue is by running rm -rf .testmondata*.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 26 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@christianbundy @smitp It would be great if you could try the latest pre-release and report if the problem is fixed.

There is a pre-release ta py pi with https://github.com/tarpas/pytest-testmon/commit/a34500e2ab47a260378ee8a60653ddb7f644ed64 . There is a big hope this should go away.

Yup! I’m running in Docker (based on python:3.10.8-slim-bullseye), my dependencies (all using the latest patch versions) are:

pytest = "~=7.2"
pytest-django = "~=4.5"
pytest-testmon = "~=1.4"
pytest-watcher = "~=0.2.6"
pytest-xdist = "~=3.1"

Pytest options:

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "my_app.settings"
addopts = "-Wignore --no-migrations --reuse-db --testmon"
python_classes = "" # disable pytest-specific class discovery
python_files = ["*_tests.py", "test_*.py", "tests.py"]
python_functions = "" # disable pytest-specific function discovery

My conftest.py:

import pytest


@pytest.fixture(autouse=True)
def enable_db_access_for_all_tests(db):
    pass

And my command:

watchgod pytest.main