make --doctest-glob multi-allowed
This commit is contained in:
parent
46039f8687
commit
0ea8dc0d40
|
@ -15,7 +15,7 @@ def pytest_addoption(parser):
|
||||||
help="run doctests in all .py modules",
|
help="run doctests in all .py modules",
|
||||||
dest="doctestmodules")
|
dest="doctestmodules")
|
||||||
group.addoption("--doctest-glob",
|
group.addoption("--doctest-glob",
|
||||||
action="store", default="test*.txt", metavar="pat",
|
action="append", default=["test*.txt"], metavar="pat",
|
||||||
help="doctests file matching pattern, default: test*.txt",
|
help="doctests file matching pattern, default: test*.txt",
|
||||||
dest="doctestglob")
|
dest="doctestglob")
|
||||||
group.addoption("--doctest-ignore-import-errors",
|
group.addoption("--doctest-ignore-import-errors",
|
||||||
|
@ -29,11 +29,20 @@ def pytest_collect_file(path, parent):
|
||||||
if path.ext == ".py":
|
if path.ext == ".py":
|
||||||
if config.option.doctestmodules:
|
if config.option.doctestmodules:
|
||||||
return DoctestModule(path, parent)
|
return DoctestModule(path, parent)
|
||||||
elif (path.ext in ('.txt', '.rst') and parent.session.isinitpath(path)) or \
|
elif _is_doctest(config, path, parent):
|
||||||
path.check(fnmatch=config.getvalue("doctestglob")):
|
|
||||||
return DoctestTextfile(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")
|
||||||
|
for glob in globs:
|
||||||
|
if path.check(fnmatch=glob):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class ReprFailDoctest(TerminalRepr):
|
class ReprFailDoctest(TerminalRepr):
|
||||||
|
|
||||||
def __init__(self, reprlocation, lines):
|
def __init__(self, reprlocation, lines):
|
||||||
|
|
Loading…
Reference in New Issue