tarpas / pytest-testmon

Selects tests affected by changed files. Executes the right tests first. Continuous test runner when used with pytest-watch.
https://testmon.org
MIT License
800 stars 54 forks source link

.testmondata does not get flushed at exit #233

Open szym opened 1 week ago

szym commented 1 week ago

What is your setup and what steps did you do?

The easiest way to reproduce is to run pytest --testmon in an environment that has: pytest==8.2.2 pytest-mock==3.14.0 pytest-testmon==2.1.1

I tried to make it even smaller and found that this reduced part of pytest-mock is enough to cause trouble:

from dataclasses import dataclass
from typing import Iterator

@dataclass
class Foo: pass

T = Iterator[Foo]

What was the outcome? Once this code is loaded by pytest, it no longer deletes the instance of TestmonData and consequently its db (apparently, Python does not promise __del__ will ever be called unless an instance is explicitly deleted). In result, the sqlite connection is not flushed. The .testmondata will still recover on the next run, but when trying to archive it (as part of CI), it makes a bit frustrating to have to carry its -wal and -shm files as well.

What did you expect instead? .testmondata to be flushed. Probably simplest to makeTestmonData.close_connection() explicitly close the sqlite3 connection.

What is your operating system and it's version please? macOS 11.7

szym commented 1 week ago

My workaround right now is to add to conftest.py:

import pytest

def pytest_unconfigure(config):
    if hasattr(config, "testmon_data"):
        config.testmon_data.db.con.close()