initial stab at a nose plugin

This commit is contained in:
Kurt Grandis
2010-03-06 03:56:30 -05:00
commit bd4bc4bdfc
2 changed files with 73 additions and 0 deletions

61
nose_exclude.py Normal file
View File

@@ -0,0 +1,61 @@
import os
import logging
from nose.plugins import Plugin
log = logging.getLogger('nose.plugins.nose-exclude')
class NoseExclude(Plugin):
def options(self, parser, env=os.environ):
"""Define the command line options for the plugin."""
super(NoseExclude, self).options(parser, env)
parser.add_option(
"--exclude-dirs", action="append",
dest="exclude_dirs",
help="Directories to exclude from test discovery. \
Paths can be relative to current working directory \
or an absolute path. [NOSE_EXCLUDE_DIRS]")
def configure(self, options, conf):
"""Configure plugin based on command line options"""
super(NoseExclude, self).configure(options, conf)
#TODO add logging
if not options.exclude_dirs:
self.enabled = False
return
self.enabled = True
root = os.getcwd()
log.debug('cwd: %s' % root)
cleaned_dirs = []
for d in options.exclude_dirs:
if os.path.isabs(d):
cleaned_dirs.append(d)
elif os.path.isdir(d):
#see if it's relative
new_abs_d = os.path.join(root,d)
cleaned_dirs.append(new_abs_d)
else:
#bad path
#TODO
pass
self.exclude_dirs = cleaned_dirs
exclude_str = "excluding dirs: %s" % ",".join(self.exclude_dirs)
log.debug(exclude_str)
def wantDirectory(self, dirname):
"""Check if directory is eligible for test discovery"""
if dirname in self.exclude_dirs:
log.debug("excluded: %s" % dirname)
return False
else:
return True

12
setup.py Normal file
View File

@@ -0,0 +1,12 @@
from setuptools import setup
setup(
name = "nose-exclude",
version = "0.1.1",
py_modules = ['nose_exclude'],
entry_points = {
'nose.plugins': ['nose-exclude = nose_exclude:NoseExclude']
},
install_requires = ['nose'],
)