diff --git a/README.rst b/README.rst index 8445449..ce5d631 100644 --- a/README.rst +++ b/README.rst @@ -74,11 +74,12 @@ To exclude test functions: 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=``. - +``--exclude-dir=`` and ``--exclude-test=`` can be set by the environment +variables ``NOSE_EXCLUDE_DIRS`` and ``NOSE_EXCLUDE_TESTS`` respectively. +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 ======================== diff --git a/nose_exclude.py b/nose_exclude.py index 396c28e..b03f3dc 100644 --- a/nose_exclude.py +++ b/nose_exclude.py @@ -25,6 +25,10 @@ class NoseExclude(Plugin): exclude_dirs = env.get('NOSE_EXCLUDE_DIRS', '') env_dirs.extend(exclude_dirs.split(';')) + if 'NOSE_EXCLUDE_TESTS' in env: + exclude_tests = env.get('NOSE_EXCLUDE_TESTS', '') + env_tests.extend(exclude_tests.split(';')) + parser.add_option( str("--exclude-dir"), action="append", dest="exclude_dirs", diff --git a/tests.py b/tests.py index 688daea..e3a2360 100644 --- a/tests.py +++ b/tests.py @@ -144,6 +144,21 @@ class TestNoseExcludeTestNegative(PluginTester, unittest.TestCase): assert 'Ran 3 tests' in self.output +class TestNoseExcludeTestsEnvVariables(PluginTester, unittest.TestCase): + """Test nose-exclude's use of environment variables""" + + activate = "-v" + plugins = [NoseExclude()] + suitepath = os.path.join(os.getcwd(), 'test_dirs/unittest') + env = {'NOSE_EXCLUDE_TESTS': + 'test_dirs.unittest.tests.UnitTests.test_a;' + 'test_dirs.unittest.tests.test_c' + } + + def test_test_excluded(self): + assert 'Ran 1 test' in self.output + + class TestNoseExcludeMultipleTest(PluginTester, unittest.TestCase): """Test nose-exclude multiple tests"""