Skip to content

Commit

Permalink
fix(backend, tests): move prefect fixtures
Browse files Browse the repository at this point in the history
Run Prefect only when required.
Since we do autouse, it would also run during benchmark tests which is
not required.

Signed-off-by: Fatih Acar <[email protected]>
  • Loading branch information
fatih-acar committed Jan 21, 2025
1 parent 078bc3c commit 00f3de9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
14 changes: 0 additions & 14 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
from neo4j import GraphDatabase
from neo4j.exceptions import ServiceUnavailable
from prefect import settings as prefect_settings
from prefect.logging.loggers import disable_run_logger
from prefect.testing.utilities import prefect_test_harness
from testcontainers.core.container import DockerContainer
from testcontainers.core.waiting_utils import wait_for_logs

Expand Down Expand Up @@ -202,18 +200,6 @@ async def do_register_core_models_schema(branch: Branch) -> SchemaBranch:
return schema_branch


@pytest.fixture(scope="session", autouse=True)
def prefect_test_fixture():
with prefect_test_harness():
yield


@pytest.fixture(scope="session")
def prefect_test(prefect_test_fixture):
with disable_run_logger():
yield


@pytest.fixture(scope="session")
def neo4j(request: pytest.FixtureRequest, load_settings_before_session) -> Optional[dict[int, int]]:
if not INFRAHUB_USE_TEST_CONTAINERS or config.SETTINGS.database.db_type == "memgraph":
Expand Down
15 changes: 15 additions & 0 deletions backend/tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from prefect.logging.loggers import disable_run_logger
from prefect.testing.utilities import prefect_test_harness


@pytest.fixture(scope="session", autouse=True)
def prefect_test_fixture():
with prefect_test_harness():
yield


@pytest.fixture(scope="session")
def prefect_test(prefect_test_fixture):
with disable_run_logger():
yield
14 changes: 14 additions & 0 deletions backend/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
import yaml
from infrahub_sdk.uuidt import UUIDT
from prefect.logging.loggers import disable_run_logger
from prefect.testing.utilities import prefect_test_harness
from pytest import TempPathFactory

from infrahub import config
Expand Down Expand Up @@ -121,3 +123,15 @@ def git_repo_car_dealership(git_sources_dir: Path) -> FileRepo:
"""Simple Git Repository used for testing."""

return FileRepo(name="car-dealership", sources_directory=git_sources_dir)


@pytest.fixture(scope="session", autouse=True)
def prefect_test_fixture():
with prefect_test_harness():
yield


@pytest.fixture(scope="session")
def prefect_test(prefect_test_fixture):
with disable_run_logger():
yield
14 changes: 14 additions & 0 deletions backend/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from infrahub_sdk import Config, InfrahubClient
from infrahub_sdk.uuidt import UUIDT
from neo4j._codec.hydration.v1 import HydrationHandler
from prefect.logging.loggers import disable_run_logger
from prefect.testing.utilities import prefect_test_harness
from pytest_httpx import HTTPXMock

from infrahub import config
Expand Down Expand Up @@ -87,6 +89,18 @@ def neo4j_factory():
return hydration_scope._graph_hydrator


@pytest.fixture(scope="session", autouse=True)
def prefect_test_fixture():
with prefect_test_harness():
yield


@pytest.fixture(scope="session")
def prefect_test(prefect_test_fixture):
with disable_run_logger():
yield


@pytest.fixture
def git_sources_dir(default_branch, tmp_path: Path) -> Path:
source_dir = tmp_path / "sources"
Expand Down

0 comments on commit 00f3de9

Please sign in to comment.