otko/tests/conftest.py

30 lines
928 B
Python
Raw Normal View History

"""Shared pytest configuration.
2026-09-08 02:12:15 -04:00
The GUI suite is headless by default: unless the caller already chose a
platform, ``QT_QPA_PLATFORM=offscreen`` is set here, before pytest-qt
builds its session ``QApplication``. An explicit caller value is respected.
OpenseesPy is a process-global singleton, so a lazy autouse guard wipes the
domain after every test. The import is inside the teardown so that
``tests/unit`` never imports the solver.
2026-09-08 02:12:15 -04:00
"""
from __future__ import annotations
import os
from collections.abc import Iterator
2026-09-08 02:12:15 -04:00
import pytest
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
2026-09-08 02:12:15 -04:00
@pytest.fixture(autouse=True)
def _wipe_opensees_domain() -> Iterator[None]:
"""Wipe the OpenseesPy domain after a test if the solver was imported."""
yield
2026-09-08 02:12:15 -04:00
try:
from openseespy.opensees import wipe
except Exception: # pragma: no cover - solver not installed / import side effects
2026-09-08 02:12:15 -04:00
return
wipe()