Merge branch 'fix-all-skipped-but-none-exist'
This commit is contained in:
commit
97c89e6dc3
1
AUTHORS
1
AUTHORS
|
@ -79,6 +79,7 @@ Ross Lawley
|
||||||
Ryan Wooden
|
Ryan Wooden
|
||||||
Samuele Pedroni
|
Samuele Pedroni
|
||||||
Tom Viner
|
Tom Viner
|
||||||
|
Thomas Grainger
|
||||||
Trevor Bekolay
|
Trevor Bekolay
|
||||||
Wouter van Ackooy
|
Wouter van Ackooy
|
||||||
David Díaz-Barquero
|
David Díaz-Barquero
|
||||||
|
|
|
@ -3,12 +3,18 @@
|
||||||
|
|
||||||
**Bug Fixes**
|
**Bug Fixes**
|
||||||
|
|
||||||
*
|
* Text documents without any doctests no longer appear as "skipped".
|
||||||
|
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
*
|
*
|
||||||
|
|
||||||
|
.. _#1580: https://github.com/pytest-dev/pytest/issues/1580
|
||||||
|
|
||||||
|
.. _@graingert: https://github.com/graingert
|
||||||
|
|
||||||
|
|
||||||
2.9.2
|
2.9.2
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
|
|
@ -144,20 +144,18 @@ def get_optionflags(parent):
|
||||||
return flag_acc
|
return flag_acc
|
||||||
|
|
||||||
|
|
||||||
class DoctestTextfile(DoctestItem, pytest.Module):
|
class DoctestTextfile(pytest.Module):
|
||||||
|
obj = None
|
||||||
|
|
||||||
def runtest(self):
|
def collect(self):
|
||||||
import doctest
|
import doctest
|
||||||
fixture_request = _setup_fixtures(self)
|
|
||||||
|
|
||||||
# inspired by doctest.testfile; ideally we would use it directly,
|
# inspired by doctest.testfile; ideally we would use it directly,
|
||||||
# but it doesn't support passing a custom checker
|
# but it doesn't support passing a custom checker
|
||||||
text = self.fspath.read()
|
text = self.fspath.read()
|
||||||
filename = str(self.fspath)
|
filename = str(self.fspath)
|
||||||
name = self.fspath.basename
|
name = self.fspath.basename
|
||||||
globs = dict(getfixture=fixture_request.getfuncargvalue)
|
globs = {'__name__': '__main__'}
|
||||||
if '__name__' not in globs:
|
|
||||||
globs['__name__'] = '__main__'
|
|
||||||
|
|
||||||
optionflags = get_optionflags(self)
|
optionflags = get_optionflags(self)
|
||||||
runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
|
runner = doctest.DebugRunner(verbose=0, optionflags=optionflags,
|
||||||
|
@ -165,8 +163,8 @@ class DoctestTextfile(DoctestItem, pytest.Module):
|
||||||
|
|
||||||
parser = doctest.DocTestParser()
|
parser = doctest.DocTestParser()
|
||||||
test = parser.get_doctest(text, globs, name, filename, 0)
|
test = parser.get_doctest(text, globs, name, filename, 0)
|
||||||
_check_all_skipped(test)
|
if test.examples:
|
||||||
runner.run(test)
|
yield DoctestItem(test.name, self, runner, test)
|
||||||
|
|
||||||
|
|
||||||
def _check_all_skipped(test):
|
def _check_all_skipped(test):
|
||||||
|
|
|
@ -14,13 +14,16 @@ class TestDoctests:
|
||||||
>>> i-1
|
>>> i-1
|
||||||
4
|
4
|
||||||
""")
|
""")
|
||||||
|
|
||||||
for x in (testdir.tmpdir, checkfile):
|
for x in (testdir.tmpdir, checkfile):
|
||||||
#print "checking that %s returns custom items" % (x,)
|
#print "checking that %s returns custom items" % (x,)
|
||||||
items, reprec = testdir.inline_genitems(x)
|
items, reprec = testdir.inline_genitems(x)
|
||||||
assert len(items) == 1
|
assert len(items) == 1
|
||||||
assert isinstance(items[0], DoctestTextfile)
|
assert isinstance(items[0], DoctestItem)
|
||||||
|
assert isinstance(items[0].parent, DoctestTextfile)
|
||||||
|
# Empty file has no items.
|
||||||
items, reprec = testdir.inline_genitems(w)
|
items, reprec = testdir.inline_genitems(w)
|
||||||
assert len(items) == 1
|
assert len(items) == 0
|
||||||
|
|
||||||
def test_collect_module_empty(self, testdir):
|
def test_collect_module_empty(self, testdir):
|
||||||
path = testdir.makepyfile(whatever="#")
|
path = testdir.makepyfile(whatever="#")
|
||||||
|
@ -595,6 +598,11 @@ class TestDoctestSkips:
|
||||||
reprec = testdir.inline_run("--doctest-modules")
|
reprec = testdir.inline_run("--doctest-modules")
|
||||||
reprec.assertoutcome(skipped=1)
|
reprec.assertoutcome(skipped=1)
|
||||||
|
|
||||||
|
def test_vacuous_all_skipped(self, testdir, makedoctest):
|
||||||
|
makedoctest('')
|
||||||
|
reprec = testdir.inline_run("--doctest-modules")
|
||||||
|
reprec.assertoutcome(passed=0, skipped=0)
|
||||||
|
|
||||||
|
|
||||||
class TestDoctestAutoUseFixtures:
|
class TestDoctestAutoUseFixtures:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue