virtualEnvironment/lib/python2.7/site-packages/coverage/execfile.py
def run_python_file(filename, args, package=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.
    `args` is the argument array to present as sys.argv, including the first
    element naming the file being executed.  `package` is the name of the
    enclosing package, if any.

    """
    # Create a module to serve as __main__
    old_main_mod = sys.modules['__main__']
    main_mod = imp.new_module('__main__')
    sys.modules['__main__'] = main_mod
    main_mod.__file__ = filename
    if package:
        main_mod.__package__ = package
    main_mod.__builtins__ = BUILTINS

    # Set sys.argv properly.
    old_argv = sys.argv
    sys.argv = args

    try:
        # Make a code object somehow.
        if filename.endswith(".pyc") or filename.endswith(".pyo"):
            code = make_code_from_pyc(filename)
        else:
            code = make_code_from_py(filename)

        # Execute the code object.
        try:
            exec_code_object(code, main_mod.__dict__)
        except SystemExit:
            # The user called sys.exit().  Just pass it along to the upper
            # layers, where it will be handled.
            raise
        except:
            # Something went wrong while executing the user code.
            # Get the exc_info, and pack them into an exception that we can
            # throw up to the outer loop.  We peel two layers off the traceback
            # so that the coverage.py code doesn't appear in the final printed
            # traceback.
            typ, err, tb = sys.exc_info()
            raise ExceptionDuringRun(typ, err, tb.tb_next.tb_next)
    finally:
        # Restore the old __main__
        sys.modules['__main__'] = old_main_mod

        # Restore the old argv and path
        sys.argv = old_argv
def run_python_file(filename, args, package=None):
    # Create a module to serve as __main__
    old_main_mod = sys.modules['__main__']
    main_mod = imp.new_module('__main__')
    sys.modules['__main__'] = main_mod
    main_mod.__file__ = filename
    if package:
        main_mod.__package__ = package
    main_mod.__builtins__ = BUILTINS

    # Set sys.argv properly.
    old_argv = sys.argv
    sys.argv = args

    try:
        # Make a code object somehow.
        if filename.endswith(".pyc") or filename.endswith(".pyo"):
            code = make_code_from_pyc(filename)
        else:
            code = make_code_from_py(filename)

        # Execute the code object.
        try:
            exec_code_object(code, main_mod.__dict__)
        except SystemExit:
            # The user called sys.exit().  Just pass it along to the upper
            # layers, where it will be handled.
            raise
        except:
            # Something went wrong while executing the user code.
            # Get the exc_info, and pack them into an exception that we can
            # throw up to the outer loop.  We peel two layers off the traceback
            # so that the coverage.py code doesn't appear in the final printed
            # traceback.
            typ, err, tb = sys.exc_info()
            raise ExceptionDuringRun(typ, err, tb.tb_next.tb_next)
    finally:
        # Restore the old __main__
        sys.modules['__main__'] = old_main_mod

        # Restore the old argv and path
        sys.argv = old_argv
def run_python_file ( filename , args , package = None ) : # Create a module to serve as __main__ old_main_mod = sys . modules [ '__main__' ] main_mod = imp . new_module ( '__main__' ) sys . modules [ '__main__' ] = main_mod main_mod . __file__ = filename if package : main_mod . __package__ = package main_mod . __builtins__ = BUILTINS # Set sys.argv properly. old_argv = sys . argv sys . argv = args try : # Make a code object somehow. if filename . endswith ( ".pyc" ) or filename . endswith ( ".pyo" ) : code = make_code_from_pyc ( filename ) else : code = make_code_from_py ( filename ) # Execute the code object. try : exec_code_object ( code , main_mod . __dict__ ) except SystemExit : # The user called sys.exit().  Just pass it along to the upper # layers, where it will be handled. raise except : # Something went wrong while executing the user code. # Get the exc_info, and pack them into an exception that we can # throw up to the outer loop.  We peel two layers off the traceback # so that the coverage.py code doesn't appear in the final printed # traceback. typ , err , tb = sys . exc_info ( ) raise ExceptionDuringRun ( typ , err , tb . tb_next . tb_next ) finally : # Restore the old __main__ sys . modules [ '__main__' ] = old_main_mod # Restore the old argv and path sys . argv = old_argv
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.
    `args` is the argument array to present as sys.argv, including the first
    element naming the file being executed.  `package` is the name of the
    enclosing package, if any.
Run a python file as if it were the main program on the command line .