Resolving Issue #6: enable environment variable usage.

This commit is contained in:
Kurt Grandis 2012-08-13 16:38:58 -04:00
parent de9264c323
commit 6a6444b09b
4 changed files with 49 additions and 0 deletions

View File

@ -51,6 +51,15 @@ where ``exclude_dirs.txt`` might look like: ::
# Comments
test_dirs/test_not_me
Using Environment Variables
---------------------------
``--exclude-dir=`` can be set by the environment variables ``NOSE_EXCLUDE_DIRS``.
Multiple exclude paths may be entered by separating them using a ``;``.
The environment variable ``NOSE_EXCLUDE_DIRS_FILE`` when set to the path of a
file-based exclusion list functions as though it were passed in with ``--exclude-dir-file=``.
Nose Configuration Files
========================

View File

@ -9,9 +9,14 @@ class NoseExclude(Plugin):
def options(self, parser, env=os.environ):
"""Define the command line options for the plugin."""
super(NoseExclude, self).options(parser, env)
env_dirs = []
if 'NOSE_EXCLUDE_DIRS' in env:
exclude_dirs = env.get('NOSE_EXCLUDE_DIRS','')
env_dirs.extend(exclude_dirs.split(';'))
parser.add_option(
"--exclude-dir", action="append",
dest="exclude_dirs",
default=env_dirs,
help="Directory to exclude from test discovery. \
Path can be relative to current working directory \
or an absolute path. May be specified multiple \
@ -20,6 +25,7 @@ class NoseExclude(Plugin):
parser.add_option(
"--exclude-dir-file", type="string",
dest="exclude_dir_file",
default=env.get('NOSE_EXCLUDE_DIRS_FILE', False),
help="A file containing a list of directories to exclude \
from test discovery. Paths can be relative to current \
working directory or an absolute path. \

View File

@ -59,5 +59,32 @@ class TestNoseExcludeDirs_Relative_Args_Mixed(PluginTester, unittest.TestCase):
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeEnvVariables(PluginTester, unittest.TestCase):
"""Test nose-exclude's use of environment variables"""
#args = ['--exclude-dir=test_dirs/test_not_me']
activate = "-v"
plugins = [NoseExclude()]
suitepath = os.path.join(os.getcwd(), 'test_dirs')
env = {'NOSE_EXCLUDE_DIRS':'test_dirs/build;test_dirs/test_not_me'}
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
class TestNoseExcludeDirsEnvFile(PluginTester, unittest.TestCase):
"""Test nose-exclude directories using relative paths passed
by file specified by environment variable
"""
activate = "-v"
plugins = [NoseExclude()]
env = {'NOSE_EXCLUDE_DIRS_FILE':'test_dirs/exclude_dirs.txt'}
suitepath = os.path.join(os.getcwd(), 'test_dirs')
def test_proper_dirs_omitted(self):
assert "FAILED" not in self.output
if __name__ == '__main__':
unittest.main()

7
tox.ini Normal file
View File

@ -0,0 +1,7 @@
[tox]
envlist = py25,py26,py27
[testenv]
deps=nose
commands=
python setup.py test