summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Szakmeister <john@szakmeister.net>2015-10-20 07:13:27 -0400
committerJohn Szakmeister <john@szakmeister.net>2015-10-20 07:13:27 -0400
commit9ccf568e7f7a8c48d235e779f2add2481859d81c (patch)
tree4964851c4037b59757ebe67bbe552875236790d9
parentd6642085a87cece41edc3808749f68d7b9a5ecd9 (diff)
downloadnose-9ccf568e7f7a8c48d235e779f2add2481859d81c.tar.gz
Fix #931: duplicate __init__ modules can be picked up
The short form here is that when setting up ignores, you may allow __init__.py to be included unexpectedly. Since we generally use loadTestsFromName(), the package should be imported first which will handle the __init__.py case. Therefore, let's always ignore it in the loadTestsFromDir() method. Just to make sure that we ignore the correct files, we need to run the entry name through src() to make sure we handle the situation correctly on other platforms (like Jython).
-rw-r--r--functional_tests/test_loader.py5
-rw-r--r--nose/loader.py4
2 files changed, 7 insertions, 2 deletions
diff --git a/functional_tests/test_loader.py b/functional_tests/test_loader.py
index 81aaa7b..104f220 100644
--- a/functional_tests/test_loader.py
+++ b/functional_tests/test_loader.py
@@ -5,6 +5,7 @@ from difflib import ndiff
from cStringIO import StringIO
from nose.config import Config
+from nose.plugins.allmodules import AllModules
from nose.plugins.manager import PluginManager
from nose.plugins.skip import Skip
from nose import loader
@@ -64,9 +65,11 @@ class TestNoseTestLoader(unittest.TestCase):
self.assertEqual(res.testsRun, 1)
def test_fixture_context(self):
+ config = Config(ignoreFiles=[],
+ plugins=PluginManager(plugins=[AllModules()]))
res = unittest.TestResult()
wd = os.path.join(support, 'package2')
- l = loader.TestLoader(workingDir=wd)
+ l = loader.TestLoader(config=config, workingDir=wd)
dir_suite = l.loadTestsFromName('.')
dir_suite(res)
diff --git a/nose/loader.py b/nose/loader.py
index 3744e54..a579372 100644
--- a/nose/loader.py
+++ b/nose/loader.py
@@ -21,7 +21,7 @@ from nose.config import Config
from nose.importer import Importer, add_path, remove_path
from nose.selector import defaultSelector, TestAddress
from nose.util import func_lineno, getpackage, isclass, isgenerator, \
- ispackage, regex_last_key, resolve_name, transplant_func, \
+ ispackage, regex_last_key, resolve_name, src, transplant_func, \
transplant_class, test_address
from nose.suite import ContextSuiteFactory, ContextList, LazySuite
from nose.pyversion import sort_list, cmp_to_key
@@ -153,6 +153,8 @@ class TestLoader(unittest.TestLoader):
# http://code.google.com/p/python-nose/issues/detail?id=82
if entry.startswith('.'):
continue
+ if src(entry) == '__init__.py':
+ continue
entry_path = op_abspath(op_join(path, entry))
is_file = op_isfile(entry_path)
wanted = False