# Created: 2026-06-09
# (c) Copyright 2024 ETH Zurich, Milos Katanic
# https://doi.org/10.5905/ethz-1007-842
#
# Licensed under the GNU General Public License v3.0;
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# https://www.gnu.org/licenses/gpl-3.0.en.html
#
# This software is distributed "AS IS", WITHOUT WARRANTY OF ANY KIND,
# express or implied. See the License for specific language governing
# permissions and limitations under the License.
"""Shared pytest fixtures.
Two safeguards for the headless test suite:
1. The default ``config`` enables ``small_signal_analysis`` so an interactive
``run.py`` shows the modal report and participation figures. That path ends in
a blocking ``plt.show`` and must never fire during tests — so the autouse
fixture forces the flag off. A test that exercises the analysis opts back in
with ``small_signal_analysis=True`` in ``config.updated(...)``.
2. Importing ``pydynamicestimator.run`` selects the interactive TkAgg backend.
The fixture re-forces the non-interactive Agg backend before every test so a
stray ``plt.show(block=True)`` is a no-op and can never halt the suite.
"""
import os
import matplotlib
import pytest
os.environ.setdefault("MPLBACKEND", "Agg")
matplotlib.use("Agg", force=True)
from pydynamicestimator.config import config
[docs]
@pytest.fixture(autouse=True)
def _headless_no_blocking_plots():
matplotlib.use("Agg", force=True)
config.small_signal_analysis = False
yield