@@ -105,6 +105,24 @@ def pytest_addoption(parser):
105
105
)
106
106
107
107
108
+ def ignore_doctest_warning (item : pytest .Item , path : str , message : str ) -> None :
109
+ """Ignore doctest warning.
110
+
111
+ Parameters
112
+ ----------
113
+ item : pytest.Item
114
+ pytest test item.
115
+ path : str
116
+ Module path to Python object, e.g. "pandas.core.frame.DataFrame.append". A
117
+ warning will be filtered when item.name ends with in given path. So it is
118
+ sufficient to specify e.g. "DataFrame.append".
119
+ message : str
120
+ Message to be filtered.
121
+ """
122
+ if item .name .endswith (path ):
123
+ item .add_marker (pytest .mark .filterwarnings (f"ignore:{ message } " ))
124
+
125
+
108
126
def pytest_collection_modifyitems (items , config ):
109
127
skip_slow = config .getoption ("--skip-slow" )
110
128
only_slow = config .getoption ("--only-slow" )
@@ -117,13 +135,34 @@ def pytest_collection_modifyitems(items, config):
117
135
(pytest .mark .db , "db" , skip_db , "--skip-db" ),
118
136
]
119
137
138
+ # Warnings from doctests that can be ignored; place reason in comment above.
139
+ # Each entry specifies (path, message) - see the ignore_doctest_warning function
140
+ ignored_doctest_warnings = [
141
+ # Deprecations where the docstring will emit a warning
142
+ ("DataFrame.append" , "The frame.append method is deprecated" ),
143
+ ("Series.append" , "The series.append method is deprecated" ),
144
+ ("dtypes.common.is_categorical" , "is_categorical is deprecated" ),
145
+ ("Categorical.replace" , "Categorical.replace is deprecated" ),
146
+ ("dtypes.common.is_extension_type" , "'is_extension_type' is deprecated" ),
147
+ ("Index.is_mixed" , "Index.is_mixed is deprecated" ),
148
+ ("MultiIndex._is_lexsorted" , "MultiIndex.is_lexsorted is deprecated" ),
149
+ # Docstring divides by zero to show behavior difference
150
+ ("missing.mask_zero_div_zero" , "divide by zero encountered" ),
151
+ # Docstring demonstrates the call raises a warning
152
+ ("_validators.validate_axis_style_args" , "Use named arguments" ),
153
+ ]
154
+
120
155
for item in items :
121
156
if config .getoption ("--doctest-modules" ) or config .getoption (
122
157
"--doctest-cython" , default = False
123
158
):
124
159
# autouse=True for the add_doctest_imports can lead to expensive teardowns
125
160
# since doctest_namespace is a session fixture
126
161
item .add_marker (pytest .mark .usefixtures ("add_doctest_imports" ))
162
+
163
+ for path , message in ignored_doctest_warnings :
164
+ ignore_doctest_warning (item , path , message )
165
+
127
166
# mark all tests in the pandas/tests/frame directory with "arraymanager"
128
167
if "/frame/" in item .nodeid :
129
168
item .add_marker (pytest .mark .arraymanager )
0 commit comments