Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 11 additions & 10 deletions tests/ai_guard/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from collections.abc import Generator
from typing import Any
import pytest


def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
"""Mark all ai_guard tests as xfail when generating cassettes."""
if getattr(config.option, "generate_cassettes", False):
for item in items:
item.add_marker(
pytest.mark.xfail(
reason="Generating cassettes - test assertions are not evaluated",
strict=False,
)
)
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo) -> Generator[None, Any, None]:
"""When generating cassettes, don't let setup/assertion failures fail the run."""
outcome = yield
if item.config.option.generate_cassettes and call.when in ("setup", "call") and call.excinfo is not None:
report = outcome.get_result()
report.outcome = "skipped"
current_filename, lineno, _ = item.location
report.longrepr = (current_filename, lineno + 1, "Generating cassettes - test assertions are not evaluated")
21 changes: 10 additions & 11 deletions tests/integration_frameworks/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Generator

from typing import Any
import pytest

from utils.docker_fixtures import (
Expand All @@ -10,16 +10,15 @@
from utils import context, scenarios, logger


def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
"""Mark all integration_frameworks tests as xfail when generating cassettes."""
if config.option.generate_cassettes:
for item in items:
item.add_marker(
pytest.mark.xfail(
reason="Generating cassettes - test assertions are not evaluated",
strict=False,
)
)
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo) -> Generator[None, Any, None]:
"""When generating cassettes, don't let setup/assertion failures fail the run."""
outcome = yield
if item.config.option.generate_cassettes and call.when in ("setup", "call") and call.excinfo is not None:
Comment thread
cbeauchesne marked this conversation as resolved.
report = outcome.get_result()
report.outcome = "skipped"
Comment thread
cbeauchesne marked this conversation as resolved.
current_filename, lineno, _ = item.location
report.longrepr = (current_filename, lineno + 1, "Generating cassettes - test assertions are not evaluated")


@pytest.fixture
Expand Down
21 changes: 11 additions & 10 deletions tests/parametric/test_llm_observability/conftest.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from collections.abc import Generator
from typing import Any
import pytest


def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
"""Mark all llm_observability tests as xfail when generating cassettes."""
if config.option.generate_cassettes:
for item in items:
item.add_marker(
pytest.mark.xfail(
reason="Generating cassettes - test assertions are not evaluated",
strict=False,
)
)
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item: pytest.Item, call: pytest.CallInfo) -> Generator[None, Any, None]:
"""When generating cassettes, don't let setup/assertion failures fail the run."""
outcome = yield
if item.config.option.generate_cassettes and call.when in ("setup", "call") and call.excinfo is not None:
report = outcome.get_result()
report.outcome = "skipped"
current_filename, lineno, _ = item.location
report.longrepr = (current_filename, lineno + 1, "Generating cassettes - test assertions are not evaluated")


@pytest.fixture
Expand Down
Loading