"""Shared test fixtures for codeflash-python tests."""

from __future__ import annotations

import sys
from importlib.util import find_spec
from pathlib import Path

import pytest


def has_module(name: str) -> bool:
    """Check whether an optional dependency is importable (for skipif markers)."""
    return find_spec(name) is not None


# Make the code_to_optimize fixture package importable by tests that need it
# (e.g. test_comparator.py, test_trace_benchmarks.py).
_TESTS_DIR = str(Path(__file__).resolve().parent)
if _TESTS_DIR not in sys.path:
    sys.path.insert(0, _TESTS_DIR)


@pytest.fixture
def benchmark():
    """Passthrough benchmark fixture matching the codeflash-benchmark plugin fallback."""
    return lambda func, *args, **kwargs: func(*args, **kwargs)
