Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #7 #497

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions nose/plugins/doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def options(self, parser, env):
help="Find fixtures for a doctest file in module "
"with this name appended to the base name "
"of the doctest file")
parser.add_option('--doctest-options', action="append",
dest="doctestOptions",
metavar="OPTIONS",
help="Specify options to pass to doctest. " +
"Eg. '+ELLIPSIS,+NORMALIZE_WHITESPACE'")
# Set the default as a list, if given in env; otherwise
# an additional value set on the command line will cause
# an error.
Expand All @@ -186,7 +191,23 @@ def configure(self, options, config):
self.extension = tolist(options.doctestExtension)
self.fixtures = options.doctestFixtures
self.finder = doctest.DocTestFinder()

self.optionflags = 0
if options.doctestOptions:
flags = ",".join(options.doctestOptions).split(',')
for flag in flags:
try:
if flag.startswith('+'):
self.optionflags |= getattr(doctest, flag[1:])
elif flag.startswith('-'):
self.optionflags &= ~getattr(doctest, flag[1:])
else:
raise ValueError(
"Must specify doctest options with starting " +
"'+' or '-'. Got %s" % (flag,))
except AttributeError:
raise ValueError("Unknown doctest option %s" %
(flag[1:],))

def prepareTestLoader(self, loader):
"""Capture loader's suiteClass.

Expand Down Expand Up @@ -222,7 +243,9 @@ def loadTestsFromModule(self, module):
continue
if not test.filename:
test.filename = module_file
cases.append(DocTestCase(test, result_var=self.doctest_result_var))
cases.append(DocTestCase(test,
optionflags=self.optionflags,
result_var=self.doctest_result_var))
if cases:
yield self.suiteClass(cases, context=module, can_split=False)

Expand Down Expand Up @@ -265,6 +288,7 @@ def loadTestsFromFile(self, filename):
if test.examples:
case = DocFileCase(
test,
optionflags=self.optionflags,
setUp=getattr(fixture_context, 'setup_test', None),
tearDown=getattr(fixture_context, 'teardown_test', None),
result_var=self.doctest_result_var)
Expand All @@ -285,7 +309,7 @@ def makeTest(self, obj, parent):
for test in doctests:
if len(test.examples) == 0:
continue
yield DocTestCase(test, obj=obj,
yield DocTestCase(test, obj=obj, optionflags=self.optionflags,
result_var=self.doctest_result_var)

def matches(self, name):
Expand Down