Commits

Ned Batchelder committed 4e67741

Don't touch files as unexecuted if they were omitted. Fixes #218.

  • Participants
  • Parent commits fb57726

Comments (0)

Files changed (3)

 - Improved the branch coverage mechanism, fixing `issue 175`_.
 
 - Running code with ``coverage run -m`` now behaves more like Python does,
-  setting sys.path properly, which fixes `issue 207`_ and `issue 242`.
+  setting sys.path properly, which fixes `issue 207`_ and `issue 242`_.
+
+- Omitting files within a tree specified with the ``source`` option would
+  cause them to be incorrectly marked as unexecuted, as described in
+  `issue 218`_.  This is now fixed.
 
 - When running a threaded program under the Python tracer, coverage would issue
   a spurious warning about the trace function changing: "Trace function
 .. _issue 175: https://bitbucket.org/ned/coveragepy/issue/175/branch-coverage-gets-confused-in-certain
 .. _issue 207: https://bitbucket.org/ned/coveragepy/issue/207/run-m-cannot-find-module-or-package-in
 .. _issue 242: https://bitbucket.org/ned/coveragepy/issue/242/running-a-two-level-package-doesnt-work
+.. _issue 218: https://bitbucket.org/ned/coveragepy/issue/218/run-command-does-not-respect-the-omit-flag
+
 
 Version 3.6 --- 5 January 2013
 ------------------------------

File coverage/control.py

             for src in self.source:
                 for py_file in find_python_files(src):
                     py_file = self.file_locator.canonical_filename(py_file)
+
+                    if self.omit_match and self.omit_match.match(py_file):
+                        # Turns out this file was omitted, so don't pull it
+                        # back in as unexecuted.
+                        continue
+
                     self.data.touch_file(py_file)
 
             self._measured = False

File tests/test_api.py

         self.filenames_not_in(result, "p1a p1c p2a othera osa")
 
     def test_omit_and_include(self):
-        result = self.coverage_usepkgs( include=["*/p1*"], omit=["*/p1a.py"])
+        result = self.coverage_usepkgs(include=["*/p1*"], omit=["*/p1a.py"])
         self.filenames_in(result, "p1b")
         self.filenames_not_in(result, "p1a p1c p2a p2b")
 
         self.filenames_in(lines, "p1b")
         self.filenames_not_in(lines, "p1a p1c p2a p2b othera otherb osa osb")
 
+    def test_source_package_part_omitted(self):
+        # https://bitbucket.org/ned/coveragepy/issue/218
+        # Used to be if you omitted something executed and inside the source,
+        # then after it was executed but not recorded, it would be found in
+        # the search for unexecuted files, and given a score of 0%.
+        lines = self.coverage_usepkgs(source=["pkg1"], omit=["pkg1/p1b.py"])
+        self.filenames_in(lines, "p1a")
+        self.filenames_not_in(lines, "p1b")
+        self.assertEqual(lines['p1c'], 0)
+
 
 class ReportIncludeOmitTest(OmitIncludeTestsMixin, CoverageTest):
     """Tests of the report include/omit functionality."""