Skip to content

Commit cb7ee53

Browse files
committed
ENH: allow filtering out import errors on get_public_object
get_public_object calls `getattr(module, name)`. This can emit a DeprecationWarning, so do it under config.user_context_manager() so that users can filter out these warnings.
1 parent 90ac42a commit cb7ee53

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

scipy_doctest/frontend.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ def find_doctests(module, strategy=None,
7070
return tests
7171

7272
if strategy == "api":
73-
(items, names), failures = get_public_objects(module,
74-
skiplist=config.skiplist)
73+
74+
with config.user_context_mgr():
75+
# user_context_mgr may want to e.g. filter warnings on imports?
76+
(items, names), failures = get_public_objects(module,
77+
skiplist=config.skiplist)
7578
if failures:
7679
mesg = "\n".join([_[2] for _ in failures])
7780
raise ValueError(mesg)

scipy_doctest/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def numpy_rndm_state():
9898

9999

100100
@contextmanager
101-
def noop_context_mgr(test):
101+
def noop_context_mgr(test=None):
102102
"""Do nothing.
103103
104104
This is a stub context manager to serve as a default for
@@ -117,7 +117,7 @@ def np_errstate():
117117

118118

119119
@contextmanager
120-
def warnings_errors(test):
120+
def warnings_errors(test=None):
121121
"""Temporarily turn all warnings to errors."""
122122
with warnings.catch_warnings():
123123
warnings.simplefilter('error', Warning)

0 commit comments

Comments
 (0)