Merge pull request #1297 from nicoddemus/multi-doctest-glob
Multiple --doctest-glob arguments
This commit is contained in:
commit
c367180ab2
1
AUTHORS
1
AUTHORS
|
@ -45,6 +45,7 @@ Jaap Broekhuizen
|
|||
Jan Balster
|
||||
Janne Vanhala
|
||||
Jason R. Coombs
|
||||
Joshua Bronson
|
||||
Jurko Gospodnetić
|
||||
Katarzyna Jachim
|
||||
Kevin Cox
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ def pytest_addoption(parser):
|
|||
help="run doctests in all .py modules",
|
||||
dest="doctestmodules")
|
||||
group.addoption("--doctest-glob",
|
||||
action="store", 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",
|
||||
|
@ -29,11 +29,20 @@ def pytest_collect_file(path, parent):
|
|||
if path.ext == ".py":
|
||||
if config.option.doctestmodules:
|
||||
return DoctestModule(path, parent)
|
||||
elif (path.ext in ('.txt', '.rst') and parent.session.isinitpath(path)) or \
|
||||
path.check(fnmatch=config.getvalue("doctestglob")):
|
||||
elif _is_doctest(config, path, parent):
|
||||
return DoctestTextfile(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") or ['test*.txt']
|
||||
for glob in globs:
|
||||
if path.check(fnmatch=glob):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class ReprFailDoctest(TerminalRepr):
|
||||
|
||||
def __init__(self, reprlocation, lines):
|
||||
|
|
|
@ -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)::
|
||||
|
||||
|
|
|
@ -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 *'])
|
||||
|
|
Loading…
Reference in New Issue