Files
ss-tools/backend/conftest.py
busya 488a8f349b test(backend): raise coverage to 95%+ statements and branches (97.8%/95.0%)
- ~60 new/extended test files across api, core, plugins, services, schemas:
  routes, superset clients, task_manager, lineage, git, translate,
  dashboard-testing, load-testing, migration, llm_analysis, scheduler, ssl
- .coveragerc: enable branch coverage; exclude src/__tests__ (test files)
  and src/scripts (CLI/ops tools) from the denominator
- bug fixes found while testing:
  * settings: PUT /settings/reports registered under duplicated prefix
  * schemas/lineage: FleetReportDTO missing run_status (route always 500)
  * dashboard_testing/baseline_inheritance: visual entry read wrong field
  * superset_client/_databases: logger extra name shadowed LogRecord attr
  * routes/datasets: _yaml_string_paths recursion without yield from
  * translate/sql_generator: restore explicit-type timestamp contract
  * baseline_catalog: remove unreachable dashboard_id fallback
- conftest fixes: pytest_plugins to rootdir conftest (pytest 9), test
  filename collision, TMPDIR-safe integration fixtures
2026-08-19 17:14:32 +03:00

46 lines
2.1 KiB
Python

# conftest.py at backend root
# Prevents pytest collection errors caused by duplicate test module names
# between the root tests/ directory and co-located src/<module>/__tests__/ directories.
# Without this, pytest sees e.g. tests/test_auth.py and src/core/auth/__tests__/test_auth.py
# and raises "import file mismatch" because both map to module name "test_auth".
import os
import tempfile
from cryptography.fernet import Fernet
# Set ENCRYPTION_KEY for EncryptionManager before any module imports
# Required by LLMProviderService which is imported via route modules
os.environ.setdefault("ENCRYPTION_KEY", Fernet.generate_key().decode())
# Test DB defaults. This conftest loads BEFORE tests/conftest.py, and the
# integration fixture plugins below import src.core.database at module load
# time (which requires DATABASE_URL). Same temp-file SQLite scheme as
# tests/conftest.py so unit runs keep identical behavior.
_TEST_DB_FILE = tempfile.NamedTemporaryFile(suffix="_ss_tools_root.db", delete=False)
_TEST_DB_PATH = _TEST_DB_FILE.name
_TEST_DB_FILE.close()
os.environ.setdefault("DATABASE_URL", f"sqlite:///{_TEST_DB_PATH}")
os.environ.setdefault("AUTH_DATABASE_URL", f"sqlite:///{_TEST_DB_PATH}")
# Integration-test fixture plugins. Declared at the top-level (rootdir) conftest
# because pytest >= 8.2 raises an error for `pytest_plugins` defined in a
# non-top-level conftest (previously a deprecation warning). Fixture definitions
# live in tests/integration/fixtures/*.py and only start Docker containers when a
# test actually requests them, so unit runs are unaffected.
pytest_plugins = [
"tests.integration.fixtures.network",
"tests.integration.fixtures.postgres",
"tests.integration.fixtures.pki",
"tests.integration.fixtures.config",
"tests.integration.fixtures.superset",
]
# Files in tests/ that clash with __tests__/ co-located tests.
# norecursedirs=["__tests__"] in pyproject.toml prevents collection from src/__tests__/
# at the directory level; this list handles edge cases where explicit file paths
# are collected.
collect_ignore = [
os.path.join("tests", "schemas", "test_auth.py"),
]