Skip to content

Commit 4e5cb07

Browse files
committed
ENH: allow # may vary at both source and want
1 parent c1d4b25 commit 4e5cb07

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

scipy_doctest/impl.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ def get_examples(self, string, name='<string>'):
514514
"""
515515
stopwords = self.config.stopwords
516516
pseudocode = self.config.pseudocode
517+
rndm_markers = self.config.rndm_markers
517518

518519
SKIP = doctest.OPTIONFLAGS_BY_NAME['SKIP']
519520
keep_skipping_this_block = False
@@ -537,6 +538,11 @@ def get_examples(self, string, name='<string>'):
537538
# NB: Could have just skipped it via `continue`.
538539
example.options[SKIP] = True
539540

541+
if any(word in example.source for word in rndm_markers):
542+
# Found a `# may vary`. Do not check the output (but do check
543+
# that the source is valid python).
544+
example.want += " # _ignore\n"
545+
540546
if any(word in example.source for word in stopwords):
541547
# Found a stopword. Do not check the output (but do check
542548
# that the source is valid python).

scipy_doctest/tests/test_skipmarkers.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,25 @@ def test_may_vary_source(self):
161161
filename='none', lineno=0)
162162

163163
runner = DebugDTRunner()
164-
with pytest.raises(doctest.DocTestFailure):
164+
runner.run(test)
165+
166+
# one example tried, of which zero failed
167+
assert runner.get_history() == {'may_vary_source': (0, 1)}
168+
169+
def test_may_vary_syntax_error(self):
170+
# `# may vary` markers do not mask syntax errors, unlike `# doctest: +SKIP`
171+
string = ">>> 1 += 2 # may vary\n"
172+
string += "42\n"
173+
174+
parser = DTParser()
175+
test = parser.get_doctest(string, globs={},
176+
name='may_vary_err',
177+
filename='none', lineno=0)
178+
179+
runner = DebugDTRunner()
180+
with pytest.raises(Exception) as exc_info:
165181
runner.run(test)
182+
assert exc_info.type == doctest.UnexpectedException
166183

167184

168185
string='''\

0 commit comments

Comments
 (0)