From b8280720c567674749570d1743b91fb5f68b96b3 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Wed, 1 Jun 2016 15:36:42 +0100 Subject: [PATCH] Don't mark empty doctest files as skipped, fixes #1578 --- _pytest/doctest.py | 15 ++++++--------- testing/test_doctest.py | 12 ++++++++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/_pytest/doctest.py b/_pytest/doctest.py index a57f7a4949e..58aff350039 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -5,7 +5,7 @@ import pytest from _pytest._code.code import TerminalRepr, ReprFileLocation, ExceptionInfo -from _pytest.python import FixtureRequest +from _pytest.python import FixtureRequest, PyCollector @@ -144,20 +144,17 @@ def get_optionflags(parent): return flag_acc -class DoctestTextfile(DoctestItem, pytest.Module): +class DoctestTextfile(pytest.File, PyCollector): - def runtest(self): + def collect(self): import doctest - fixture_request = _setup_fixtures(self) # inspired by doctest.testfile; ideally we would use it directly, # but it doesn't support passing a custom checker text = self.fspath.read() filename = str(self.fspath) name = self.fspath.basename - globs = dict(getfixture=fixture_request.getfuncargvalue) - if '__name__' not in globs: - globs['__name__'] = '__main__' + globs = {'__name__': '__main__'} optionflags = get_optionflags(self) runner = doctest.DebugRunner(verbose=0, optionflags=optionflags, @@ -165,8 +162,8 @@ def runtest(self): parser = doctest.DocTestParser() test = parser.get_doctest(text, globs, name, filename, 0) - _check_all_skipped(test) - runner.run(test) + if test.examples: + yield DoctestItem(test.name, self, runner, test) def _check_all_skipped(test): diff --git a/testing/test_doctest.py b/testing/test_doctest.py index a4821ee4c9e..816f069d319 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -14,13 +14,16 @@ def test_collect_testtextfile(self, testdir): >>> i-1 4 """) + for x in (testdir.tmpdir, checkfile): #print "checking that %s returns custom items" % (x,) items, reprec = testdir.inline_genitems(x) 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) - assert len(items) == 1 + assert len(items) == 0 def test_collect_module_empty(self, testdir): path = testdir.makepyfile(whatever="#") @@ -595,6 +598,11 @@ def test_all_skipped(self, testdir, makedoctest): reprec = testdir.inline_run("--doctest-modules") 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: