From acd286f82fac4eba30c3cf26f4281e39330340ca Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 17 Nov 2010 14:33:21 +0100 Subject: [PATCH] run doctests in .txt/.rst files directly specified on command line irrespective of "test*.txt" pattern. --- _pytest/doctest.py | 3 ++- doc/index.txt | 2 +- testing/test_doctest.py | 6 +++--- tox.ini | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/_pytest/doctest.py b/_pytest/doctest.py index e1ed3782c..6f09fb0eb 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -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): diff --git a/doc/index.txt b/doc/index.txt index fd41792a3..4790aceaa 100644 --- a/doc/index.txt +++ b/doc/index.txt @@ -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: diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 7d4d5f80b..a7a30edbf 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -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 @@ -18,6 +16,8 @@ class TestDoctests: 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="#") diff --git a/tox.ini b/tox.ini index 941bd9c86..164bd6065 100644 --- a/tox.ini +++ b/tox.ini @@ -57,6 +57,6 @@ commands= [pytest] minversion=2.0 plugins=pytester -#addopts= -rxf --pyargs +addopts= -rxf --pyargs rsyncdirs=tox.ini pytest.py _pytest testing