Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mark empty doctest files as skipped, fixes #1578 #1580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,27 @@ def get_optionflags(parent):
return flag_acc


class DoctestTextfile(DoctestItem, pytest.Module):
class DoctestTextfile(pytest.Module):
obj = None

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,
checker=_get_checker())

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):
Expand Down
12 changes: 10 additions & 2 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it was a test bug

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

# 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="#")
Expand Down Expand Up @@ -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:

Expand Down