Skip to content

Commit

Permalink
Fix migration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Dec 14, 2023
1 parent a830aa0 commit 0904efb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
10 changes: 9 additions & 1 deletion tests/migration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from core.model import json_serializer
from tests.fixtures.database import ApplicationFixture, DatabaseFixture
from tests.fixtures.services import ServicesFixture

if TYPE_CHECKING:
from pytest_alembic import MigrationContext
Expand All @@ -20,8 +21,15 @@
import alembic.config


pytest_plugins = [
"tests.fixtures.services",
]


@pytest.fixture(scope="function")
def application() -> Generator[ApplicationFixture, None, None]:
def application(
services_fixture: ServicesFixture,
) -> Generator[ApplicationFixture, None, None]:
app = ApplicationFixture.create()
yield app
app.close()
Expand Down
12 changes: 8 additions & 4 deletions tests/migration/test_instance_init_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from io import StringIO
from multiprocessing import Process
from unittest.mock import Mock
from unittest.mock import MagicMock, Mock

from pytest_alembic import MigrationContext
from sqlalchemy import inspect
Expand All @@ -11,15 +11,19 @@
from core.model import SessionManager
from scripts import InstanceInitializationScript
from tests.fixtures.database import ApplicationFixture
from tests.fixtures.services import mock_services_container


def _run_script() -> None:
try:
# Run the script, capturing the log output
script = InstanceInitializationScript()
# Capturing the log output
stream = StringIO()
logging.basicConfig(stream=stream, level=logging.INFO, force=True)
script.run()

mock_services = MagicMock()
with mock_services_container(mock_services):
script = InstanceInitializationScript()
script.run()

# Set our exit code to the number of upgrades we ran
sys.exit(stream.getvalue().count("Running upgrade"))
Expand Down

0 comments on commit 0904efb

Please sign in to comment.