-
Notifications
You must be signed in to change notification settings - Fork 458
Expand file tree
/
Copy pathconftest.py
More file actions
88 lines (69 loc) · 2.65 KB
/
Copy pathconftest.py
File metadata and controls
88 lines (69 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""conftest.py - pytest local plugins and fixtures"""
import os
from contextlib import contextmanager
import matplotlib as mpl
import numpy as np
import pytest
import control
# some common pytest marks. These can be used as test decorators or in
# pytest.param(marks=)
slycotonly = pytest.mark.skipif(
not control.exception.slycot_check(), reason="slycot not installed")
cvxoptonly = pytest.mark.skipif(
not control.exception.cvxopt_check(), reason="cvxopt not installed")
@pytest.fixture(scope="session", autouse=True)
def control_defaults():
"""Make sure the testing session always starts with the defaults.
This should be the first fixture initialized, so that all other
fixtures see the general defaults (unless they set them themselves)
even before importing control/__init__. Enforce this by adding it as an
argument to all other session scoped fixtures.
"""
control.reset_defaults()
the_defaults = control.config.defaults.copy()
yield
# assert that nothing changed it without reverting
assert control.config.defaults == the_defaults
@pytest.fixture(scope="function")
def editsdefaults():
"""Make sure any changes to the defaults only last during a test."""
restore = control.config.defaults.copy()
yield
control.config.defaults.clear()
control.config.defaults.update(restore)
@pytest.fixture(scope="function")
def mplcleanup():
"""Clean up any plots and changes a test may have made to matplotlib.
compare matplotlib.testing.decorators.cleanup() but as a fixture instead
of a decorator.
"""
save = mpl.units.registry.copy()
try:
yield
finally:
mpl.units.registry.clear()
mpl.units.registry.update(save)
mpl.pyplot.close("all")
@pytest.fixture(scope="function")
def legacy_plot_signature():
"""Turn off warnings for calls to plotting functions with old signatures"""
import warnings
warnings.filterwarnings(
'ignore', message='passing systems .* is deprecated',
category=DeprecationWarning)
warnings.filterwarnings(
'ignore', message='.* return values of .* is deprecated',
category=DeprecationWarning)
yield
warnings.resetwarnings()
@pytest.fixture(scope="function")
def ignore_future_warning():
"""Turn off warnings for functions that generate FutureWarning"""
import warnings
warnings.filterwarnings(
'ignore', message='.*deprecated', category=FutureWarning)
yield
warnings.resetwarnings()
# Allow pytest.mark.slow to mark slow tests (skip with pytest -m "not slow")
def pytest_configure(config):
config.addinivalue_line("markers", "slow: mark test as slow to run")