Skip to content

Commit f9d7065

Browse files
authored
Merge pull request #170 from scipy/may_vary_at_source
ENH: allow `# may vary` at both source and `want`
2 parents 3de1c2d + 702fbbb commit f9d7065

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Its main features are
4848
>>> np.random.randint(100)
4949
42 # may vary
5050
```
51-
Note that the markers (by default, `"# may vary"` and `"# random"`) are applied
52-
to an example's output, not its source.
51+
Note that the markers (by default, `"# may vary"` and `"# random"`) can be applied
52+
to either an example's output, or its source.
5353

5454
Also note a difference with respect to the standard `# doctest: +SKIP`: the latter
5555
skips the example entirely, while these additional markers only skip checking

scipy_doctest/impl.py

+6
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

+18-1
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)