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
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ uv run ty check drift/ tests/ # Type check
### Unit Tests

```bash
uv run python -m unittest discover -s tests/unit -v
uv run pytest tests/unit/ -v

# Run a specific test file
uv run python -m unittest tests.unit.test_json_schema_helper -v
uv run python -m unittest tests.unit.test_adapters -v
uv run pytest tests/unit/test_json_schema_helper.py -v
uv run pytest tests/unit/test_adapters.py -v

# Run a specific test class or function
uv run pytest tests/unit/test_metrics.py::TestMetricsCollector -v
uv run pytest tests/unit/test_metrics.py::TestMetricsCollector::test_record_spans_exported -v
```

### Integration Tests

```bash
# Flask/FastAPI integration tests
timeout 30 uv run python -m unittest discover -s tests/integration -v
timeout 30 uv run pytest tests/integration/ -v
```

### E2E Tests
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ dev = [
"python-jsonpath>=0.10",
"ruff>=0.8.0",
"ty>=0.0.1a7",
"pytest>=8.0.0",
"pytest>=8.0.0,<9.0.0",
"pytest-mock>=3.15.0",
]

[project.urls]
Expand Down
46 changes: 46 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Pytest configuration and fixtures for Drift Python SDK tests."""

from __future__ import annotations

import os
import tempfile
from collections.abc import Generator
from pathlib import Path
from typing import TYPE_CHECKING

import pytest

if TYPE_CHECKING:
from drift.core.metrics import MetricsCollector
from drift.core.tracing.adapters import InMemorySpanAdapter


@pytest.fixture
def temp_dir() -> Generator[Path, None, None]:
"""Create a temporary directory for test files."""
with tempfile.TemporaryDirectory() as tmpdir:
yield Path(tmpdir)


@pytest.fixture
def original_cwd() -> Generator[str, None, None]:
"""Save and restore the current working directory."""
cwd = os.getcwd()
yield cwd
os.chdir(cwd)


@pytest.fixture
def in_memory_adapter() -> InMemorySpanAdapter:
"""Create a fresh InMemorySpanAdapter for testing."""
from drift.core.tracing.adapters import InMemorySpanAdapter

return InMemorySpanAdapter()


@pytest.fixture
def metrics_collector() -> MetricsCollector:
"""Create a fresh MetricsCollector for testing."""
from drift.core.metrics import MetricsCollector

return MetricsCollector()
Loading