Skip to content

Commit

Permalink
fix CI failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanCardin committed Mar 7, 2024
1 parent 48c03c2 commit dc966b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
10 changes: 10 additions & 0 deletions src/pytest_mock_resources/compat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import importlib.resources
import sys

from pytest_mock_resources.compat.import_ import ImportAdaptor

# isort: split
Expand Down Expand Up @@ -70,6 +73,13 @@
pymysql = ImportAdaptor("pymysql", "mysql")


def get_resource(package: str) -> str:
if sys.version_info >= (3, 9):
return str(importlib.resources.files(package))

return str(importlib.resources.path(package, "").__enter__())


__all__ = [
"sqlalchemy",
"psycopg2",
Expand Down
24 changes: 10 additions & 14 deletions src/pytest_mock_resources/fixture/postgresql.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import importlib.resources
import inspect
import logging
from typing import cast
from typing import cast, TYPE_CHECKING

import pytest
import sqlalchemy
from sqlalchemy import text
from sqlalchemy.engine import Connection, Engine

from pytest_mock_resources.compat import get_resource
from pytest_mock_resources.container.base import (
async_retry,
DEFAULT_RETRIES,
Expand All @@ -29,6 +29,9 @@
normalize_actions,
)

if TYPE_CHECKING:
from sqlalchemy.ext.asyncio import AsyncEngine

log = logging.getLogger(__name__)


Expand Down Expand Up @@ -280,11 +283,9 @@ def _async_scope_fixture(
cleanup_databases: bool = False,
name="postgres",
):
from sqlalchemy.ext.asyncio import AsyncEngine

async def fixture(pmr_postgres_config):
root_engine = cast(
AsyncEngine,
"AsyncEngine",
get_sqlalchemy_engine(
pmr_postgres_config,
pmr_postgres_config.root_database,
Expand Down Expand Up @@ -314,7 +315,7 @@ async def fixture(pmr_postgres_config):
assert template_database

engine = cast(
AsyncEngine,
"AsyncEngine",
get_sqlalchemy_engine(
pmr_postgres_config, template_database, **engine_kwargs, async_=True
),
Expand Down Expand Up @@ -342,10 +343,8 @@ async def _async_fixture(
engine_manager: EngineManager,
cleanup_databases: bool = False,
):
from sqlalchemy.ext.asyncio import AsyncEngine

root_engine = cast(
AsyncEngine,
"AsyncEngine",
get_sqlalchemy_engine(
pmr_config,
pmr_config.root_database,
Expand Down Expand Up @@ -480,13 +479,10 @@ def _sync_drop_database(conn: Connection, database_name: str):


def find_caller_globals():
ignore_paths = (
str(importlib.resources.files("pytest_mock_resources")),
str(importlib.resources.files("pdb")),
)
ignore_path = get_resource("pytest_mock_resources")
stack = inspect.stack()
for item in stack:
if item.filename.startswith(ignore_paths):
if item.filename.startswith(ignore_path) or item.filename.endswith("pdb.py"):
continue

frame = item.frame
Expand Down

0 comments on commit dc966b3

Please sign in to comment.