summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
Diffstat (limited to 'coverage')
-rw-r--r--coverage/cmdline.py13
-rw-r--r--coverage/control.py6
-rw-r--r--coverage/execfile.py9
3 files changed, 19 insertions, 9 deletions
diff --git a/coverage/cmdline.py b/coverage/cmdline.py
index cb1d7a3..ac80310 100644
--- a/coverage/cmdline.py
+++ b/coverage/cmdline.py
@@ -1,6 +1,6 @@
"""Command-line support for Coverage."""
-import optparse, sys, traceback
+import optparse, os, sys, traceback
from coverage.backward import sorted # pylint: disable=W0622
from coverage.execfile import run_python_file, run_python_module
@@ -549,15 +549,21 @@ class CoverageScript(object):
def do_execute(self, options, args):
"""Implementation of 'coverage run'."""
+ # Set the first path element properly.
+ old_path0 = sys.path[0]
+
# Run the script.
self.coverage.start()
code_ran = True
try:
try:
if options.module:
+ sys.path[0] = ''
self.run_python_module(args[0], args)
else:
- self.run_python_file(args[0], args)
+ filename = args[0]
+ sys.path[0] = os.path.abspath(os.path.dirname(filename))
+ self.run_python_file(filename, args)
except NoSource:
code_ran = False
raise
@@ -566,6 +572,9 @@ class CoverageScript(object):
if code_ran:
self.coverage.save()
+ # Restore the old path
+ sys.path[0] = old_path0
+
def do_debug(self, args):
"""Implementation of 'coverage debug'."""
diff --git a/coverage/control.py b/coverage/control.py
index afb6137..09bd75f 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -499,6 +499,12 @@ class coverage(object):
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
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 587c2d3..fbb49b2 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -65,6 +65,7 @@ def run_python_module(modulename, args):
openfile.close()
# Finally, hand the file off to run_python_file for execution.
+ pathname = os.path.abspath(pathname)
args[0] = pathname
run_python_file(pathname, args, package=packagename)
@@ -87,14 +88,9 @@ def run_python_file(filename, args, package=None):
main_mod.__package__ = package
main_mod.__builtins__ = BUILTINS
- # Set sys.argv and the first path element properly.
+ # Set sys.argv properly.
old_argv = sys.argv
- old_path0 = sys.path[0]
sys.argv = args
- if package:
- sys.path[0] = ''
- else:
- sys.path[0] = os.path.abspath(os.path.dirname(filename))
try:
# Open the source file.
@@ -135,4 +131,3 @@ def run_python_file(filename, args, package=None):
# Restore the old argv and path
sys.argv = old_argv
- sys.path[0] = old_path0