diff options
Diffstat (limited to 'Lib/trace.py')
-rw-r--r-- | Lib/trace.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index 49ad7a8..f408705 100644 --- a/Lib/trace.py +++ b/Lib/trace.py @@ -192,11 +192,13 @@ def fullmodname(path): base = path[len(longest) + 1:] else: base = path + # the drive letter is never part of the module name + drive, base = os.path.splitdrive(base) base = base.replace(os.sep, ".") if os.altsep: base = base.replace(os.altsep, ".") filename, ext = os.path.splitext(base) - return filename + return filename.lstrip(".") class CoverageResults: def __init__(self, counts=None, calledfuncs=None, infile=None, @@ -799,7 +801,14 @@ def main(argv=None): try: with open(progname) as fp: code = compile(fp.read(), progname, 'exec') - t.run(code) + # try to emulate __main__ namespace as much as possible + globs = { + '__file__': progname, + '__name__': '__main__', + '__package__': None, + '__cached__': None, + } + t.runctx(code, globs, globs) except IOError as err: _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err)) except SystemExit: |