def discover(self, current_path, file_pattern="test*.py", top_level_dir=None): """ I take a path to a directory and discover all the tests inside files matching file_pattern. If path is not a readable directory, I raise an ImportError. If I don't find anything, I return None. Otherwise I return a GreenTestSuite """ current_abspath = os.path.abspath(current_path) if not os.path.isdir(current_abspath): raise ImportError("'{}' is not a directory".format( str(current_path))) suite = GreenTestSuite() try: for file_or_dir_name in sorted(os.listdir(current_abspath)): path = os.path.join(current_abspath, file_or_dir_name) # Recurse into directories, attempting to skip virtual environments bin_activate = os.path.join(path, "bin", "activate") if os.path.isdir(path) and not os.path.isfile(bin_activate): # Don't follow symlinks if os.path.islink(path): continue # Don't recurse into directories that couldn't be a package name if not python_dir_pattern.match(file_or_dir_name): continue subdir_suite = self.discover( path, file_pattern=file_pattern, top_level_dir=top_level_dir or current_path, ) if subdir_suite: suite.addTest(subdir_suite) elif os.path.isfile(path): # Skip irrelevant files if not python_file_pattern.match(file_or_dir_name): continue if not fnmatch(file_or_dir_name, file_pattern): continue # Try loading the file as a module module_suite = self.loadFromModuleFilename(path) if module_suite: suite.addTest(module_suite) except OSError: debug("WARNING: Test discovery failed at path {}".format( current_path)) return flattenTestSuite(suite) if suite.countTestCases() else None
def discover(self, current_path, file_pattern='test*.py', top_level_dir=None): """ I take a path to a directory and discover all the tests inside files matching file_pattern. If path is not a readable directory, I raise an ImportError. If I don't find anything, I return None. Otherwise I return a GreenTestSuite """ current_abspath = os.path.abspath(current_path) if not os.path.isdir(current_abspath): raise ImportError( "'{}' is not a directory".format(str(current_path))) suite = GreenTestSuite() try: for file_or_dir_name in sorted(os.listdir(current_abspath)): path = os.path.join(current_abspath, file_or_dir_name) # Recurse into directories, attempting to skip virtual environments bin_activate = os.path.join(path, 'bin', 'activate') if os.path.isdir(path) and not os.path.isfile(bin_activate): # Don't follow symlinks if os.path.islink(path): continue # Don't recurse into directories that couldn't be a package name if not python_dir_pattern.match(file_or_dir_name): continue subdir_suite = self.discover( path, file_pattern=file_pattern, top_level_dir=top_level_dir or current_path ) if subdir_suite: suite.addTest(subdir_suite) elif os.path.isfile(path): # Skip irrelevant files if not python_file_pattern.match(file_or_dir_name): continue if not fnmatch(file_or_dir_name, file_pattern): continue # Try loading the file as a module module_suite = self.loadFromModuleFilename(path) if module_suite: suite.addTest(module_suite) except OSError: debug("WARNING: Test discovery failed at path {}".format(current_path)) return flattenTestSuite(suite) if suite.countTestCases() else None
def discover(current_path, file_pattern='test*.py'): """ I take a path to a directory and discover all the tests inside files matching file_pattern. If path is not a readable directory, I raise an ImportError. If I don't find anything, I return None. Otherwise I return a GreenTestSuite """ current_abspath = os.path.abspath(current_path) if not os.path.isdir(current_abspath): raise ImportError("'{}' is not a directory".format(str(current_path))) suite = GreenTestSuite() for file_or_dir_name in sorted(os.listdir(current_abspath)): path = os.path.join(current_abspath, file_or_dir_name) # Recurse into directories, attempting to skip virtual environments if os.path.isdir(path) and not os.path.isfile( os.path.join(path, 'bin', 'activate')): # Don't follow symlinks if os.path.islink(path): continue # Don't recurse into directories that couldn't be a package name if not python_dir_pattern.match(file_or_dir_name): continue subdir_suite = discover(path, file_pattern=file_pattern) if subdir_suite: suite.addTest(subdir_suite) elif os.path.isfile(path): # Skip irrelevant files if not python_file_pattern.match(file_or_dir_name): continue if not fnmatch(file_or_dir_name, file_pattern): continue # Try loading the file as a module module_suite = loadFromModuleFilename(path) if module_suite: suite.addTest(module_suite) return ((suite.countTestCases() and suite) or None)
def discover(current_path, file_pattern='test*.py'): """ I take a path to a directory and discover all the tests inside files matching file_pattern. If path is not a readable directory, I raise an ImportError. If I don't find anything, I return None. Otherwise I return a GreenTestSuite """ current_abspath = os.path.abspath(current_path) if not os.path.isdir(current_abspath): raise ImportError( "'%s' is not a directory".format(str(current_path))) suite = GreenTestSuite() for file_or_dir_name in sorted(os.listdir(current_abspath)): path = os.path.join(current_abspath, file_or_dir_name) # Recurse into directories, attempting to skip virtual environments if os.path.isdir(path) and not os.path.isfile(os.path.join(path, 'bin', 'activate')): subdir_suite = discover(path, file_pattern=file_pattern) if subdir_suite: suite.addTest(subdir_suite) elif os.path.isfile(path): # Skip irrelevant files if not python_file_pattern.match(file_or_dir_name): continue if not fnmatch(file_or_dir_name, file_pattern): continue # Try loading the file as a module module_suite = loadFromModuleFilename(path) if module_suite: suite.addTest(module_suite) return ((suite.countTestCases() and suite) or None)