diff options
author | John Szakmeister <john@szakmeister.net> | 2013-09-21 08:54:26 -0700 |
---|---|---|
committer | John Szakmeister <john@szakmeister.net> | 2013-09-21 08:54:26 -0700 |
commit | 1325f7027669e1590eca7b1284c0299269a4d10b (patch) | |
tree | d2eca899a63634733258516293af48aa68aa266a | |
parent | ca46f8fcb2be895b06f0f2935bd4e8e8deb37e88 (diff) | |
parent | 7cc21d0c6f48ad6df8f49b52474e4244768fa5d0 (diff) | |
download | nose-1325f7027669e1590eca7b1284c0299269a4d10b.tar.gz |
Merge pull request #685 from lukaszb/ignore-config-files
Added NOSE_IGNORE_CONFIG_FILES as env variable option
-rw-r--r-- | doc/usage.rst | 5 | ||||
-rw-r--r-- | nose/core.py | 9 | ||||
-rw-r--r-- | unit_tests/test_core.py | 33 |
3 files changed, 45 insertions, 2 deletions
diff --git a/doc/usage.rst b/doc/usage.rst index 11e682b..57bf1ba 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -13,6 +13,11 @@ standard .ini-style config files. Put your nosetests configuration in a [nosetests] verbosity=3 with-doctest=1 + +There is also possiblity to disable configuration files loading (might be +useful when runnig i.e. tox and you don't want your global nose config file to +be used by tox). In order to ignore those configuration files simply set an +environment variable ``NOSE_IGNORE_CONFIG_FILES``. There are several other ways to use the nose test runner besides the `nosetests` script. You may use nose in a test script:: diff --git a/nose/core.py b/nose/core.py index e57a88f..4d23e38 100644 --- a/nose/core.py +++ b/nose/core.py @@ -117,11 +117,18 @@ class TestProgram(unittest.TestProgram): argv=argv, testRunner=testRunner, testLoader=testLoader, **extra_args) + def getAllConfigFiles(self, env=None): + env = env or {} + if env.get('NOSE_IGNORE_CONFIG_FILES', False): + return [] + else: + return all_config_files() + def makeConfig(self, env, plugins=None): """Load a Config, pre-filled with user config files if any are found. """ - cfg_files = all_config_files() + cfg_files = self.getAllConfigFiles(env) if plugins: manager = PluginManager(plugins=plugins) else: diff --git a/unit_tests/test_core.py b/unit_tests/test_core.py index d84c085..94b9436 100644 --- a/unit_tests/test_core.py +++ b/unit_tests/test_core.py @@ -4,7 +4,7 @@ import unittest from cStringIO import StringIO from optparse import OptionParser import nose.core -from nose.config import Config +from nose.config import Config, all_config_files from nose.tools import set_trace from mock import Bucket, MockOptParser @@ -64,5 +64,36 @@ class TestUsage(unittest.TestCase): else: del nose.__loader__ + +class DummyTestProgram(nose.core.TestProgram): + def __init__(self, *args, **kwargs): + pass + + +class TestProgramConfigs(unittest.TestCase): + + def setUp(self): + self.program = DummyTestProgram() + + def test_getAllConfigFiles(self): + self.assertEqual(self.program.getAllConfigFiles(), all_config_files()) + + def test_getAllConfigFiles_ignore_configs(self): + env = {'NOSE_IGNORE_CONFIG_FILES': 'yes'} + self.assertEqual(self.program.getAllConfigFiles(env), []) + + def test_makeConfig(self): + calls = [] + class TestProgramMock(DummyTestProgram): + def getAllConfigFiles(self, env): + calls.append(env) + return [] + + program = TestProgramMock() + env = {'foo': 'bar'} + program.makeConfig(env) + self.assertEqual(calls, [env]) + + if __name__ == '__main__': unittest.main() |