Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions infrahub_sdk/checks.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import asyncio
import importlib
import inspect
import os
import warnings
from abc import abstractmethod
Expand Down Expand Up @@ -160,7 +160,7 @@ async def run(self, data: dict | None = None) -> bool:
data = await self.collect_data()
unpacked = data.get("data") or data

if asyncio.iscoroutinefunction(self.validate):
if inspect.iscoroutinefunction(self.validate):
await self.validate(data=unpacked)
else:
self.validate(data=unpacked)
Expand Down
3 changes: 2 additions & 1 deletion infrahub_sdk/ctl/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import functools
import importlib
import inspect
import logging
import platform
import sys
Expand Down Expand Up @@ -240,7 +241,7 @@ async def _run_transform(
console.print("[yellow] you can specify a different branch with --branch")
raise typer.Abort()

if asyncio.iscoroutinefunction(transform_func):
if inspect.iscoroutinefunction(transform_func):
output = await transform_func(response)
else:
output = transform_func(response)
Expand Down
4 changes: 2 additions & 2 deletions infrahub_sdk/ctl/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import asyncio
import inspect
import logging
import traceback
from collections.abc import Callable, Coroutine
Expand Down Expand Up @@ -83,7 +83,7 @@ def catch_exception(
console = Console()

def decorator(func: Callable[..., T]) -> Callable[..., T | Coroutine[Any, Any, T]]:
if asyncio.iscoroutinefunction(func):
if inspect.iscoroutinefunction(func):

@wraps(func)
async def async_wrapper(*args: Any, **kwargs: Any) -> T:
Expand Down
4 changes: 2 additions & 2 deletions infrahub_sdk/transforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

import asyncio
import inspect
import os
from abc import abstractmethod
from typing import TYPE_CHECKING, Any
Expand Down Expand Up @@ -75,7 +75,7 @@ async def run(self, data: dict | None = None) -> Any:
unpacked = data.get("data") or data
await self.process_nodes(data=unpacked)

if asyncio.iscoroutinefunction(self.transform):
if inspect.iscoroutinefunction(self.transform):
return await self.transform(data=unpacked)

return self.transform(data=unpacked)
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ all = [
# Core optional dependencies
tests = [
"infrahub-testcontainers>=1.5.1",
"pytest",
"pytest-asyncio<0.23",
"pytest>=9.0,<9.1",
"pytest-asyncio>=1.3,<1.4",
"pytest-clarity>=1.0.1",
"pytest-cov>=4.0.0",
"pytest-httpx>=0.30",
Expand Down Expand Up @@ -108,6 +108,7 @@ exclude_lines = ["if TYPE_CHECKING:", "raise NotImplementedError()"]

[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "session"
testpaths = ["tests"]
filterwarnings = [
"ignore:Module already imported so cannot be rewritten",
Expand Down
14 changes: 6 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import asyncio
import os
from collections.abc import Generator

import pytest
import pytest_asyncio

from infrahub_sdk.ctl import config

Expand All @@ -11,13 +11,11 @@
ENV_VARS_TO_CLEAN = ["INFRAHUB_ADDRESS", "INFRAHUB_TOKEN", "INFRAHUB_BRANCH", "INFRAHUB_USERNAME", "INFRAHUB_PASSWORD"]


@pytest.fixture(scope="session")
def event_loop() -> Generator[asyncio.AbstractEventLoop]:
"""Overrides pytest default function scoped event loop"""
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close()
def pytest_collection_modifyitems(items) -> None:
pytest_asyncio_tests = (item for item in items if pytest_asyncio.is_async_test(item))
session_scope_marker = pytest.mark.asyncio(loop_scope="session")
for async_test in pytest_asyncio_tests:
async_test.add_marker(session_scope_marker, append=False)


@pytest.fixture(scope="session", autouse=True)
Expand Down
37 changes: 24 additions & 13 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.