Skip to content

Commit

Permalink
Ignore top-level setup.py when scanning for doctests.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanholek committed Jun 8, 2020
1 parent 049afb8 commit 1b93385
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nose2/plugins/doctests.py
Expand Up @@ -42,6 +42,9 @@ def handleFile(self, event):
return

name, package_path = util.name_from_path(path)
# ignore top-level setup.py which cannot be imported
if name == 'setup':
return
util.ensure_importable(package_path)
try:
module = util.module_from_name(name)
Expand Down
18 changes: 18 additions & 0 deletions nose2/tests/unit/test_doctest_plugin.py
Expand Up @@ -2,6 +2,8 @@
import sys
import doctest

from textwrap import dedent

from nose2 import events, loader, session
from nose2.plugins import doctests
from nose2.tests._common import TestCase
Expand Down Expand Up @@ -60,6 +62,22 @@ def func():
else:
self.assertEqual(event.extraTests, [])

def test_handle_file_python_setup_py(self):
# Test calling handleFile on a top-level setup.py file.
# The file should be ignored by the plugin as it cannot safely be
# imported.

setup_py = dedent("""\
'''
>>> never executed
'''
from setuptools import setup
setup(name='foo')
"""
)
event = self._handle_file("setup.py", setup_py)
self.assertEqual(event.extraTests, [])

def _handle_file(self, fpath, content):
"""Have plugin handle a file with certain content.
Expand Down

0 comments on commit 1b93385

Please sign in to comment.