Coverage for tests / integration / tools / osv_scanner / conftest.py: 96%
24 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Pytest configuration for osv_scanner integration tests."""
3from __future__ import annotations
5import shutil
6from pathlib import Path
8import pytest
11def _find_project_root() -> Path:
12 """Find project root by looking for pyproject.toml.
14 Returns:
15 Path to the project root directory.
17 Raises:
18 RuntimeError: If pyproject.toml is not found in any parent directory.
19 """
20 path = Path(__file__).resolve()
21 for parent in path.parents:
22 if (parent / "pyproject.toml").exists():
23 return parent
24 raise RuntimeError("pyproject.toml not found in parent directories")
27# Paths to test samples
28SAMPLE_DIR = _find_project_root() / "test_samples"
29OSV_SCANNER_SAMPLES = SAMPLE_DIR / "tools" / "security" / "osv_scanner"
30VIOLATION_SAMPLE = OSV_SCANNER_SAMPLES / "osv_scanner_violations.txt"
31CLEAN_SAMPLE = OSV_SCANNER_SAMPLES / "osv_scanner_clean.txt"
34@pytest.fixture
35def osv_violation_file(tmp_path: Path) -> str:
36 """Copy the osv_scanner violation sample to a temp directory.
38 The destination is named ``requirements.txt`` so osv-scanner
39 recognises it as a Python lockfile.
41 Args:
42 tmp_path: Pytest fixture providing a temporary directory.
44 Returns:
45 Path to the copied file as a string.
46 """
47 dst = tmp_path / "requirements.txt"
48 shutil.copy(VIOLATION_SAMPLE, dst)
49 return str(dst)
52@pytest.fixture
53def osv_clean_file(tmp_path: Path) -> str:
54 """Copy the osv_scanner clean sample to a temp directory.
56 The destination is named ``requirements.txt`` so osv-scanner
57 recognises it as a Python lockfile.
59 Args:
60 tmp_path: Pytest fixture providing a temporary directory.
62 Returns:
63 Path to the copied file as a string.
64 """
65 dst = tmp_path / "requirements.txt"
66 shutil.copy(CLEAN_SAMPLE, dst)
67 return str(dst)