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

.testmondata does not get flushed at exit #233

Open
szym opened this issue Jun 28, 2024 · 2 comments
Open

.testmondata does not get flushed at exit #233

szym opened this issue Jun 28, 2024 · 2 comments

Comments

@szym
Copy link

szym commented Jun 28, 2024

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
Copy link
Author

szym commented Jun 28, 2024

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()

@jacksongoode
Copy link

Is this still working for you? I've found that locally the wal and shm files get cleaned up but not when we run on CI?

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

2 participants