Skip to content

Commit

Permalink
fix: test-harness was breaking w 3.0 RC (closes #14483) (#14798)
Browse files Browse the repository at this point in the history
  • Loading branch information
glesperance authored Aug 1, 2024
1 parent f5d4892 commit 206cb23
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/prefect/testing/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
Internal utilities for tests.
"""

import atexit
import shutil
import warnings
from contextlib import ExitStack, contextmanager
from pathlib import Path
from pprint import pprint
from tempfile import TemporaryDirectory
from tempfile import mkdtemp
from typing import TYPE_CHECKING, Dict, List, Union

import prefect.context
Expand Down Expand Up @@ -118,24 +120,30 @@ def prefect_test_harness():
from prefect.server.database.dependencies import temporary_database_interface

# create temp directory for the testing database
with TemporaryDirectory() as temp_dir:
with ExitStack() as stack:
# temporarily override any database interface components
stack.enter_context(temporary_database_interface())

DB_PATH = "sqlite+aiosqlite:///" + str(Path(temp_dir) / "prefect-test.db")
stack.enter_context(
prefect.settings.temporary_settings(
# Clear the PREFECT_API_URL
restore_defaults={prefect.settings.PREFECT_API_URL},
# Use a temporary directory for the database
updates={
prefect.settings.PREFECT_API_DATABASE_CONNECTION_URL: DB_PATH,
prefect.settings.PREFECT_API_URL: None,
},
)
temp_dir = mkdtemp()

def cleanup_temp_dir(temp_dir):
shutil.rmtree(temp_dir)

atexit.register(cleanup_temp_dir, temp_dir)

with ExitStack() as stack:
# temporarily override any database interface components
stack.enter_context(temporary_database_interface())

DB_PATH = "sqlite+aiosqlite:///" + str(Path(temp_dir) / "prefect-test.db")
stack.enter_context(
prefect.settings.temporary_settings(
# Clear the PREFECT_API_URL
restore_defaults={prefect.settings.PREFECT_API_URL},
# Use a temporary directory for the database
updates={
prefect.settings.PREFECT_API_DATABASE_CONNECTION_URL: DB_PATH,
prefect.settings.PREFECT_API_URL: None,
},
)
yield
)
yield


async def get_most_recent_flow_run(client: "PrefectClient" = None):
Expand Down

0 comments on commit 206cb23

Please sign in to comment.