Skip to content

Commit

Permalink
run doctests in .txt/.rst files directly specified on command line ir…
Browse files Browse the repository at this point in the history
…respective of "test*.txt" pattern.
  • Loading branch information
hpk42 committed Nov 17, 2010
1 parent fb102a2 commit acd286f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def pytest_collect_file(path, parent):
if path.ext == ".py":
if config.option.doctestmodules:
return DoctestModule(path, parent)
elif path.check(fnmatch=config.getvalue("doctestglob")):
elif (path.ext in ('.txt', '.rst') and parent.session.isinitpath(path)) or \
path.check(fnmatch=config.getvalue("doctestglob")):
return DoctestTextfile(path, parent)

class ReprFailDoctest(TerminalRepr):
Expand Down
2 changes: 1 addition & 1 deletion doc/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ py.test: no-boilerplate testing with Python

.. note::
version 2.0 introduces ``pytest`` as the main Python import name
but for compatibility reasons you may continue to use ``py.test``
but for compatibility reasons you can continue to use ``py.test``
in your test code.

Welcome to ``py.test`` documentation:
Expand Down
6 changes: 3 additions & 3 deletions testing/test_doctest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from _pytest.doctest import DoctestModule, DoctestTextfile
import py

pytest_plugins = ["pytest_doctest"]

class TestDoctests:

def test_collect_testtextfile(self, testdir):
testdir.maketxtfile(whatever="")
w = testdir.maketxtfile(whatever="")
checkfile = testdir.maketxtfile(test_something="""
alskdjalsdk
>>> i = 5
Expand All @@ -18,6 +16,8 @@ def test_collect_testtextfile(self, testdir):
items, reprec = testdir.inline_genitems(x)
assert len(items) == 1
assert isinstance(items[0], DoctestTextfile)
items, reprec = testdir.inline_genitems(w)
assert len(items) == 1

def test_collect_module(self, testdir):
path = testdir.makepyfile(whatever="#")
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ commands=
[pytest]
minversion=2.0
plugins=pytester
#addopts= -rxf --pyargs
addopts= -rxf --pyargs
rsyncdirs=tox.ini pytest.py _pytest testing

0 comments on commit acd286f

Please sign in to comment.