Fix loading of defaults during pytest fixture setup · python-control/python-control@abf1565
@@ -28,7 +28,22 @@
2828"PendingDeprecationWarning")
2929303031-@pytest.fixture(scope="session", autouse=TEST_MATRIX_AND_ARRAY,
31+@pytest.fixture(scope="session", autouse=True)
32+def control_defaults():
33+"""Make sure the testing session always starts with the defaults.
34+35+ This should be the first fixture initialized,
36+ so that all other fixtures see the general defaults (unless they set them
37+ themselves) even before importing control/__init__. Enforce this by adding
38+ it as an argument to all other session scoped fixtures.
39+ """
40+control.reset_defaults()
41+the_defaults = control.config.defaults.copy()
42+yield
43+# assert that nothing changed it without reverting
44+assert control.config.defaults == the_defaults
45+46+@pytest.fixture(scope="function", autouse=TEST_MATRIX_AND_ARRAY,
3247 params=[pytest.param("arrayout", marks=matrixerrorfilter),
3348 pytest.param("matrixout", marks=matrixfilter)])
3449def matarrayout(request):
@@ -70,7 +85,7 @@ def check_deprecated_matrix():
7085yield
7186728773-@pytest.fixture(scope="session",
88+@pytest.fixture(scope="function",
7489 params=[p for p, usebydefault in
7590 [(pytest.param(np.array,
7691 id="arrayin"),
@@ -90,7 +105,7 @@ def editsdefaults():
90105"""Make sure any changes to the defaults only last during a test"""
91106restore = control.config.defaults.copy()
92107yield
93-control.config.defaults.update(restore)
108+control.config.defaults = restore.copy()
941099511096111@pytest.fixture(scope="function")