From 1bdf71730a3a84cfed9b81d18e5beb76943c2907 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 30 Dec 2015 18:19:08 -0200 Subject: [PATCH] Complement #1255 by adding tests and docs Fix #1242 --- AUTHORS | 1 + CHANGELOG | 3 +++ _pytest/doctest.py | 4 ++-- doc/en/doctest.rst | 5 ++++- testing/test_doctest.py | 34 ++++++++++++++++++++++++++++++++-- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index a43fd69a3..17477d59c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -45,6 +45,7 @@ Jaap Broekhuizen Jan Balster Janne Vanhala Jason R. Coombs +Joshua Bronson Jurko Gospodnetić Katarzyna Jachim Kevin Cox diff --git a/CHANGELOG b/CHANGELOG index 6d9ab3ec8..cec4138ee 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -7,6 +7,9 @@ New Features * New `pytest.mark.skip` mark, which unconditional skips marked tests. Thanks Michael Aquilina for the complete PR. +* ``--doctest-glob`` may now be passed multiple times in the command-line. + Thanks Joshua Bronson and Bruno Oliveira for the PR. + * New `-rp` and `-rP` reporting options give the summary and full output of passing tests, respectively. Thanks to David Vierra for the PR. diff --git a/_pytest/doctest.py b/_pytest/doctest.py index ed1814358..2175d8de1 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -15,7 +15,7 @@ def pytest_addoption(parser): help="run doctests in all .py modules", dest="doctestmodules") group.addoption("--doctest-glob", - action="append", default=["test*.txt"], metavar="pat", + action="append", default=[], metavar="pat", help="doctests file matching pattern, default: test*.txt", dest="doctestglob") group.addoption("--doctest-ignore-import-errors", @@ -36,7 +36,7 @@ def pytest_collect_file(path, parent): def _is_doctest(config, path, parent): if path.ext in ('.txt', '.rst') and parent.session.isinitpath(path): return True - globs = config.getoption("doctestglob") + globs = config.getoption("doctestglob") or ['test*.txt'] for glob in globs: if path.check(fnmatch=glob): return True diff --git a/doc/en/doctest.rst b/doc/en/doctest.rst index 0befa6702..1dfb73485 100644 --- a/doc/en/doctest.rst +++ b/doc/en/doctest.rst @@ -8,7 +8,10 @@ can change the pattern by issuing:: py.test --doctest-glob='*.rst' -on the command line. You can also trigger running of doctests +on the command line. Since version ``2.9``, ``--doctest-glob`` +can be given multiple times in the command-line. + +You can also trigger running of doctests from docstrings in all python modules (including regular python test modules):: diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 88d90a7bf..39e51f8ee 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -87,7 +87,7 @@ class TestDoctests: reprec.assertoutcome(failed=1) def test_new_pattern(self, testdir): - p = testdir.maketxtfile(xdoc =""" + p = testdir.maketxtfile(xdoc=""" >>> x = 1 >>> x == 1 False @@ -95,6 +95,36 @@ class TestDoctests: reprec = testdir.inline_run(p, "--doctest-glob=x*.txt") reprec.assertoutcome(failed=1) + def test_multiple_patterns(self, testdir): + """Test support for multiple --doctest-glob arguments (#1255). + """ + testdir.maketxtfile(xdoc=""" + >>> 1 + 1 + """) + testdir.makefile('.foo', test=""" + >>> 1 + 1 + """) + testdir.maketxtfile(test_normal=""" + >>> 1 + 1 + """) + expected = set(['xdoc.txt', 'test.foo', 'test_normal.txt']) + assert set(x.basename for x in testdir.tmpdir.listdir()) == expected + args = ["--doctest-glob=xdoc*.txt", "--doctest-glob=*.foo"] + result = testdir.runpytest(*args) + result.stdout.fnmatch_lines([ + '*test.foo *', + '*xdoc.txt *', + '*2 passed*', + ]) + result = testdir.runpytest() + result.stdout.fnmatch_lines([ + '*test_normal.txt *', + '*1 passed*', + ]) + def test_doctest_unexpected_exception(self, testdir): testdir.maketxtfile(""" >>> i = 0 @@ -579,4 +609,4 @@ class TestDoctestAutoUseFixtures: """) result = testdir.runpytest('--doctest-modules') assert 'FAILURES' not in str(result.stdout.str()) - result.stdout.fnmatch_lines(['*=== 1 passed in *']) \ No newline at end of file + result.stdout.fnmatch_lines(['*=== 1 passed in *'])