pytest-dev / pytest-django

A Django plugin for pytest.
https://pytest-django.readthedocs.io/
Other
1.32k stars 341 forks source link

pytest_sessionfinish cannot access database for cleanup #1123

Open syndionaldo opened 1 month ago

syndionaldo commented 1 month ago

For a given scenario, I need to undo some migrations in order to let the test database be gracefully deleted. One of those migrations creates a replication subscription that avoids the database to be removed. The solution would be to use pytest_sessionfinish hook to undo some migrations and let the teardown process to run gracefully.

However, pytest_django is avoiding the hook to complete, denying database access to it. I cannot find a way around this in order to implement this. The result: the test database need to be removed manually, which breaks the entire deployment automation.

Is there any way of doing it?