Complement #1255 by adding tests and docs

Fix #1242
This commit is contained in:
Bruno Oliveira 2015-12-30 18:19:08 -02:00
parent 0ea8dc0d40
commit 1bdf71730a
5 changed files with 42 additions and 5 deletions

View File

@ -45,6 +45,7 @@ Jaap Broekhuizen
Jan Balster
Janne Vanhala
Jason R. Coombs
Joshua Bronson
Jurko Gospodnetić
Katarzyna Jachim
Kevin Cox

View File

@ -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.

View File

@ -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

View File

@ -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)::

View File

@ -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 *'])
result.stdout.fnmatch_lines(['*=== 1 passed in *'])