Files
site/WESP_REL/tests/conftest.py
T
2026-07-17 12:57:18 +03:00

55 lines
1.7 KiB
Python

"""Общие хуки pytest для WESP."""
from __future__ import annotations
import os
from pathlib import Path
import pytest
_FIXTURES = Path(__file__).resolve().parent / "fixtures"
_WEAK_CREDENTIALS_FILE = _FIXTURES / "weak_credentials.txt"
_HARDWARE_IGNORE = {
"tests/test_gpio_controller.py",
"tests/test_hx711_wrapper.py",
}
def pytest_collection_modifyitems(config, items):
"""Дублирует ignore из pytest.ini при явном указании путей."""
ignored: list[pytest.Item] = []
kept: list[pytest.Item] = []
for item in items:
rel = item.nodeid.split("::", 1)[0].replace("\\", "/")
if rel in _HARDWARE_IGNORE:
ignored.append(item)
else:
kept.append(item)
# Убираем GPIO/HX711 только при смешанном прогоне (например «all»), не при явном выборе набора.
if ignored and kept:
items[:] = kept
def pytest_configure(config):
"""Минимальный список слабых логинов/паролей для тестов валидации admin/setup."""
os.environ.setdefault(
"WESP_WEAK_CREDENTIALS_BUILTIN_PATH",
str(_WEAK_CREDENTIALS_FILE),
)
from app.services.weak_password_blocklist import reload_weak_blocklist_for_tests
reload_weak_blocklist_for_tests()
@pytest.fixture(autouse=True)
def _reset_global_auto_updater():
"""Глобальный update.auto_updater не должен перетекать между unittest-приложениями."""
yield
try:
from app.services.auto_update_runtime import stop_update_checker
stop_update_checker()
except Exception:
pass