diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-04-20 19:10:51 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-04-20 19:10:51 -0400 |
commit | f5cfe193a73b08990fddd888167b6c6336b6803c (patch) | |
tree | a42f9e8a104eca8763ce0ded47b594c4891b1415 /coverage/execfile.py | |
parent | 351264bd7deff3fdf6e393581560b4d994c1dbfa (diff) | |
download | python-coveragepy-git-f5cfe193a73b08990fddd888167b6c6336b6803c.tar.gz |
Get sys.path right when running modules with -m, fixes #207 and #242.
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index 587c2d3c..fbb49b2a 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 |