Skip to content

Commit

Permalink
rerun matplotlib tests on failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bnavigator committed Aug 20, 2022
1 parent 0fce64b commit d08b0ae
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions control/tests/conftest.py
@@ -1,13 +1,11 @@
"""conftest.py - pytest local plugins and fixtures"""

import os
import sys
from contextlib import contextmanager

import matplotlib as mpl
import numpy as np
import pytest
import scipy as sp

import control

Expand Down Expand Up @@ -45,15 +43,15 @@ def control_defaults():
params=[pytest.param("arrayout", marks=matrixerrorfilter),
pytest.param("matrixout", marks=matrixfilter)])
def matarrayout(request):
"""Switch the config to use np.ndarray and np.matrix as returns"""
"""Switch the config to use np.ndarray and np.matrix as returns."""
restore = control.config.defaults['statesp.use_numpy_matrix']
control.use_numpy_matrix(request.param == "matrixout", warn=False)
yield
control.use_numpy_matrix(restore, warn=False)


def ismatarrayout(obj):
"""Test if the returned object has the correct type as configured
"""Test if the returned object has the correct type as configured.
note that isinstance(np.matrix(obj), np.ndarray) is True
"""
Expand All @@ -63,15 +61,15 @@ def ismatarrayout(obj):


def asmatarrayout(obj):
"""Return a object according to the configured default"""
"""Return a object according to the configured default."""
use_matrix = control.config.defaults['statesp.use_numpy_matrix']
matarray = np.asmatrix if use_matrix else np.asarray
return matarray(obj)


@contextmanager
def check_deprecated_matrix():
"""Check that a call produces a deprecation warning because of np.matrix"""
"""Check that a call produces a deprecation warning because of np.matrix."""
use_matrix = control.config.defaults['statesp.use_numpy_matrix']
if use_matrix:
with pytest.deprecated_call():
Expand All @@ -94,19 +92,20 @@ def check_deprecated_matrix():
False)]
if usebydefault or TEST_MATRIX_AND_ARRAY])
def matarrayin(request):
"""Use array and matrix to construct input data in tests"""
"""Use array and matrix to construct input data in tests."""
return request.param


@pytest.fixture(scope="function")
def editsdefaults():
"""Make sure any changes to the defaults only last during a test"""
"""Make sure any changes to the defaults only last during a test."""
restore = control.config.defaults.copy()
yield
control.config.defaults = restore.copy()


@pytest.fixture(scope="function")
@pytest.mark.flaky(reruns=2, reruns_delay=1)
def mplcleanup():
"""Clean up any plots and changes a test may have made to matplotlib.
Expand Down

0 comments on commit d08b0ae

Please sign in to comment.