summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-11-24 22:53:07 -0500
committerNed Batchelder <ned@nedbatchelder.com>2014-11-24 22:53:07 -0500
commit478677345233a9f24b4fd0335d2094e91917e6eb (patch)
tree60a286d3b0c79cae6206a2d1ff3371eaf4d9dee1 /coverage/execfile.py
parent2b369aa719d2a4b4e755c9030f1d0cc1dfeeeacb (diff)
downloadpython-coveragepy-git-478677345233a9f24b4fd0335d2094e91917e6eb.tar.gz
Cleanups from pull request 42
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 8965d207..f08b7589 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -7,18 +7,12 @@ from coverage.backward import PYC_MAGIC_NUMBER, imp, importlib_util_find_spec
from coverage.misc import ExceptionDuringRun, NoCode, NoSource
-if sys.version_info >= (3, 3):
- DEFAULT_FULLNAME = '__main__'
-else:
- DEFAULT_FULLNAME = None
-
-
class DummyLoader(object):
"""A shim for the pep302 __loader__, emulating pkgutil.ImpLoader.
Currently only implements the .fullname attribute
"""
- def __init__(self, fullname, *args):
+ def __init__(self, fullname, *_args):
self.fullname = fullname
@@ -109,7 +103,7 @@ def run_python_module(modulename, args):
run_python_file(pathname, args, package=packagename, modulename=modulename)
-def run_python_file(filename, args, package=None, modulename=DEFAULT_FULLNAME):
+def run_python_file(filename, args, package=None, modulename=None):
"""Run a python file as if it were the main program on the command line.
`filename` is the path to the file to execute, it need not be a .py file.
@@ -117,7 +111,13 @@ def run_python_file(filename, args, package=None, modulename=DEFAULT_FULLNAME):
element naming the file being executed. `package` is the name of the
enclosing package, if any.
+ `modulename` is the name of the module the file was run as.
+
"""
+ if modulename is None and sys.version_info >= (3, 3):
+ modulename = '__main__'
+
+
# Create a module to serve as __main__
old_main_mod = sys.modules['__main__']
main_mod = types.ModuleType('__main__')