From d9b92adc1e5a40b10bda5bc3e86abc5bebde2bcf Mon Sep 17 00:00:00 2001 From: John Szakmeister Date: Sun, 25 Jan 2015 06:21:43 -0500 Subject: Fix #875: nose doesn't collect tests when subpackage is given as arg When a subpackage is specified on the command line (e.g., `nosetests foo.bar`), it should pick up all the tests below the subpackage. The root of the problem came from how we resolved a filename for a package. We should really point to the package directory, instead of providing the path to the `__init__.py` file. Otherwise, we only end up attempting to select modules from the `__init__.py` instead of the whole tree underneath. We don't want to check for a path ending in `__init__.py` in `loadTestsFromModule()` because then we select the whole subtree of tests when `foo/bar/__init__.py` is specified when only tests in the __init__.py should be selected. --- nose/util.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'nose') diff --git a/nose/util.py b/nose/util.py index e6f735e..efab8fe 100644 --- a/nose/util.py +++ b/nose/util.py @@ -221,11 +221,11 @@ def getfilename(package, relativeTo=None): if relativeTo is None: relativeTo = os.getcwd() path = os.path.join(relativeTo, os.sep.join(package.split('.'))) - suffixes = ('/__init__.py', '.py') - for suffix in suffixes: - filename = path + suffix - if os.path.exists(filename): - return filename + if os.path.exists(path + '/__init__.py'): + return path + filename = path + '.py' + if os.path.exists(filename): + return filename return None -- cgit v1.2.1