Resolving Issue #6: enable environment variable usage.
This commit is contained in:
parent
de9264c323
commit
6a6444b09b
|
@ -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
|
||||
========================
|
||||
|
||||
|
|
|
@ -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. \
|
||||
|
|
27
tests.py
27
tests.py
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue