diff options
-rw-r--r-- | doc/usage.rst | 5 | ||||
-rw-r--r-- | nose/core.py | 9 | ||||
-rw-r--r-- | nose/importer.py | 2 | ||||
-rw-r--r-- | nose/plugins/xunit.py | 5 | ||||
-rw-r--r-- | unit_tests/support/init_prefix_bug/__init__.py | 1 | ||||
-rw-r--r-- | unit_tests/support/init_prefix_bug/__init__not.py | 1 | ||||
-rw-r--r-- | unit_tests/test_core.py | 33 | ||||
-rw-r--r-- | unit_tests/test_importer.py | 10 |
8 files changed, 61 insertions, 5 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/nose/importer.py b/nose/importer.py index d7d9120..e677658 100644 --- a/nose/importer.py +++ b/nose/importer.py @@ -39,7 +39,7 @@ class Importer(object): # find the base dir of the package path_parts = os.path.normpath(os.path.abspath(path)).split(os.sep) name_parts = fqname.split('.') - if path_parts[-1].startswith('__init__'): + if path_parts[-1] == '__init__.py': path_parts.pop() path_parts = path_parts[:-(len(name_parts))] dir_path = os.sep.join(path_parts) diff --git a/nose/plugins/xunit.py b/nose/plugins/xunit.py index 20fad24..7e5d793 100644 --- a/nose/plugins/xunit.py +++ b/nose/plugins/xunit.py @@ -187,8 +187,7 @@ class Xunit(Plugin): 'skipped': 0 } self.errorlist = [] - self.error_report_file = codecs.open(options.xunit_file, 'w', - self.encoding, 'replace') + self.error_report_file_name = options.xunit_file def report(self, stream): """Writes an Xunit-formatted XML file @@ -196,6 +195,8 @@ class Xunit(Plugin): The file includes a report of test errors and failures. """ + self.error_report_file = codecs.open(self.error_report_file_name, 'w', + self.encoding, 'replace') self.stats['encoding'] = self.encoding self.stats['total'] = (self.stats['errors'] + self.stats['failures'] + self.stats['passes'] + self.stats['skipped']) diff --git a/unit_tests/support/init_prefix_bug/__init__.py b/unit_tests/support/init_prefix_bug/__init__.py new file mode 100644 index 0000000..2ae2839 --- /dev/null +++ b/unit_tests/support/init_prefix_bug/__init__.py @@ -0,0 +1 @@ +pass diff --git a/unit_tests/support/init_prefix_bug/__init__not.py b/unit_tests/support/init_prefix_bug/__init__not.py new file mode 100644 index 0000000..2ae2839 --- /dev/null +++ b/unit_tests/support/init_prefix_bug/__init__not.py @@ -0,0 +1 @@ +pass 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() diff --git a/unit_tests/test_importer.py b/unit_tests/test_importer.py index 91de8a9..b8fd596 100644 --- a/unit_tests/test_importer.py +++ b/unit_tests/test_importer.py @@ -50,6 +50,16 @@ class TestImporter(unittest.TestCase): assert where in sys.path # buz has an intra-package import that sets boodle assert mod.boodle + + def test_module_init_prefix(self): + where = os.path.abspath(os.path.join(os.path.dirname(__file__), + 'support', 'init_prefix_bug')) + nose.importer.add_path(where) + mod = os.path.join(where, '__init__not.py') + fqname = 'init_prefix_bug.__init__not' + + imp = nose.importer.Importer() + mod = imp.importFromPath(mod, fqname) if __name__ == '__main__': unittest.main() |