Skip to content

Commit 03d5cb4

Browse files
committed
use pytest.mark.filterwarnings
1 parent 24e9210 commit 03d5cb4

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

docs/gallery_tests/conftest.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
"""
1111

1212
import sys
13-
import warnings
1413

1514
import pytest
1615

1716
import iris
18-
from iris._deprecation import IrisDeprecation
1917

2018
from .gallerytest_util import gallery_path
2119

@@ -41,21 +39,16 @@ def add_gallery_to_path():
4139

4240

4341
@pytest.fixture
44-
def fail_any_deprecation_warnings():
42+
def iris_future_defaults():
4543
"""
46-
Create a fixture in which any deprecation warning will cause an error.
47-
48-
The context also resets all the iris.FUTURE settings to the defaults, as
49-
otherwise changes made in one test can affect subsequent ones.
44+
Create a fixture which resets all the iris.FUTURE settings to the defaults,
45+
as otherwise changes made in one test can affect subsequent ones.
5046
5147
"""
52-
with warnings.catch_warnings():
53-
# Detect and error all and any Iris deprecation warnings.
54-
warnings.simplefilter("error", IrisDeprecation)
55-
# Run with all default settings in iris.FUTURE.
56-
default_future_kwargs = iris.Future().__dict__.copy()
57-
for dead_option in iris.Future.deprecated_options:
58-
# Avoid a warning when setting these !
59-
del default_future_kwargs[dead_option]
60-
with iris.FUTURE.context(**default_future_kwargs):
61-
yield
48+
# Run with all default settings in iris.FUTURE.
49+
default_future_kwargs = iris.Future().__dict__.copy()
50+
for dead_option in iris.Future.deprecated_options:
51+
# Avoid a warning when setting these !
52+
del default_future_kwargs[dead_option]
53+
with iris.FUTURE.context(**default_future_kwargs):
54+
yield

docs/gallery_tests/test_gallery_examples.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@
1111
from .gallerytest_util import gallery_examples, show_replaced_by_check_graphic
1212

1313

14+
@pytest.mark.filterwarnings("error::iris.IrisDeprecation")
1415
@pytest.mark.parametrize("example_code", gallery_examples())
15-
def test_plot_example(
16-
example_code, add_gallery_to_path, fail_any_deprecation_warnings
17-
):
16+
def test_plot_example(example_code, add_gallery_to_path, iris_future_defaults):
1817
module = importlib.import_module(example_code)
1918
with show_replaced_by_check_graphic(f"gallery_tests.test_{example_code}"):
2019
module.main()

0 commit comments

Comments
 (0)