-
Notifications
You must be signed in to change notification settings - Fork 14
Description
Hi!
we are currently trying to upgrade from version 0.10.6
to 0.10.7
in our project. Unfortunately we are experiencing some problems, since the pytest_alembic
tests seem to produce side effects between tests which are not getting rolled back in the new version.
An excerpt of our migration test module:
import pytest
from pytest_alembic import MigrationContext, tests
from sqlalchemy import Engine
@pytest.fixture()
def alembic_engine(our_custom_engine_fixture: Engine) -> Engine:
return our_custom_engine_fixture
@pytest.fixture()
def alembic_config() -> dict:
return {
"at_revision_data": {...}
}
def test_single_head_revision(alembic_runner: MigrationContext) -> None:
tests.test_single_head_revision(alembic_runner)
def test_upgrade(alembic_runner: MigrationContext) -> None:
tests.test_upgrade(alembic_runner)
def test_model_definitions_match_ddl(alembic_runner: MigrationContext) -> None:
tests.test_model_definitions_match_ddl(alembic_runner)
def test_up_down_consistency(alembic_runner: MigrationContext) -> None:
tests.test_up_down_consistency(alembic_runner)
We are using our own database engine throughout the entire test session, the changes are getting rolled back after each test. Before version 0.10.7
pytest_alembic rolled the database back by itself. Now our own tests are failing because there are unexpected tables in the database. We assume thats because of the following change in 0.10.7
, where connection.connect()
is replaced by connection.begin()
:
v0.10.6...v0.10.7#diff-0108f216ff6e1670b0a351075109c35eb9af378fc93b0442c06a0dd1232607b5L183-R186
We found a workaround for our use case which simply drops the alembic_version
table and all our schemas after the migration test module ran:
@pytest.fixture(autouse=True, scope="module")
def _teardown_tables(our_custom_engine_fixture: Engine) -> None:
yield
with our_custom_engine_fixture.connect() as connection:
Base.metadata.drop_all(bind=connection)
connection.execute(text("DROP TABLE IF EXISTS alembic_version"))
connection.commit()
Question is: Is this the intended behaviour of pytest_alembic
?
We are aware that our setup with a single database for the entire pytest session is a bit of a special case.
Best regards and thank you for your work providing this nice lib!