Commits

Kumar McMillan  committed b9a8fa2 Merge

Merged

  • Participants
  • Parent commits c344a45, cc95f69

Comments (0)

Files changed (3)

File nose/config.py

         self.getTestCaseNamesCompat = False
         self.includeExe = env.get('NOSE_INCLUDE_EXE',
                                   sys.platform in exe_allowed_platforms)
-        self.ignoreFiles = (re.compile(r'^\.'),
-                            re.compile(r'^_'),
-                            re.compile(r'^setup\.py$')
-                            )
+        self.ignoreFilesDefaultStrings = [r'^\.',
+                                          r'^_',
+                                          r'^setup\.py$',
+                                          ]
+        self.ignoreFiles = map(re.compile, self.ignoreFilesDefaultStrings)
         self.include = None
         self.loggingConfig = None
         self.logStream = sys.stderr
             options.where = env.get('NOSE_WHERE', None)
 
         # include and exclude also
+        if not options.ignoreFiles:
+            options.ignoreFiles = env.get('NOSE_IGNORE_FILES', [])
         if not options.include:
             options.include = env.get('NOSE_INCLUDE', [])
         if not options.exclude:
         
         if options.testMatch:
             self.testMatch = re.compile(options.testMatch)
-                
+        
+        if options.ignoreFiles:
+            self.ignoreFiles = map(re.compile, tolist(options.ignoreFiles))
+            log.info("Ignoring files matching %s", options.ignoreFiles)
+        else:
+            log.info("Ignoring files matching %s", self.ignoreFilesDefaultStrings)
+        
         if options.include:
             self.include = map(re.compile, tolist(options.include))
             log.info("Including tests matching %s", options.include)
             help="Load logging config from this file -- bypasses all other"
             " logging config settings.")
         parser.add_option(
+            "-I", "--ignore-files", action="append", dest="ignoreFiles",
+            metavar="REGEX",
+            help="Completely ignore any file that matches this regular "
+            "expression. Takes precedence over any other settings or "
+            "plugins. "
+            "Specifying this option will replace the default setting. "
+            "Specify this option multiple times "
+            "to add more regular expressions [NOSE_IGNORE_FILES]")
+        parser.add_option(
             "-e", "--exclude", action="append", dest="exclude",
             metavar="REGEX",
             help="Don't run tests that match regular "

File unit_tests/test_config.py

         c.update({'exclude':'x'})
         assert c.exclude == 'x'
 
+    def test_ignore_files_default(self):
+        """
+        The default configuration should have several ignore file settings.
+        """
+        c = nose.config.Config()
+        c.configure(['program'])
+        self.assertEqual(len(c.ignoreFiles), 3)
+    
+    def test_ignore_files_single(self):
+        """A single ignore-files flag should override the default settings.""" 
+        c = nose.config.Config()
+        c.configure(['program', '--ignore-files=a'])
+        self.assertEqual(len(c.ignoreFiles), 1)
+        aMatcher = c.ignoreFiles[0]
+        assert aMatcher.match('a')
+        assert not aMatcher.match('b')
+    
+    def test_ignore_files_multiple(self):
+        """
+        Multiple ignore-files flags should be appended together, overriding
+        the default settings.
+        """
+        c = nose.config.Config()
+        c.configure(['program', '--ignore-files=a', '-Ib'])
+        self.assertEqual(len(c.ignoreFiles), 2)
+        aMatcher, bMatcher = c.ignoreFiles
+        assert aMatcher.match('a')
+        assert not aMatcher.match('b')
+        assert bMatcher.match('b')
+        assert not bMatcher.match('a')
+    
     def test_multiple_include(self):
         c = nose.config.Config()
         c.configure(['program', '--include=a', '--include=b'])

File unit_tests/test_selector.py

     def tearDown(self):
         logging.getLogger('nose.selector').setLevel(logging.WARN)
     
+    def test_ignore_files_default(self):
+        """A default configuration should always skip some 'hidden' files."""
+        s = Selector(Config())
+        
+        assert not s.wantFile('_test_underscore.py')
+        assert not s.wantFile('.test_hidden.py')
+        assert not s.wantFile('setup.py')
+        
+    def test_ignore_files_override(self):
+        """Override the configuration to skip only specified files."""
+        c = Config()
+        c.ignoreFiles = [re.compile(r'^test_favourite_colour\.py$')]
+        s = Selector(c)
+        
+        assert s.wantFile('_test_underscore.py')
+        assert s.wantFile('.test_hidden.py')
+        assert not s.wantFile('setup.py') # Actually excluded because of testMatch
+        assert not s.wantFile('test_favourite_colour.py')
+    
     def test_exclude(self):
         s = Selector(Config())
         c = Config()