diff options
-rw-r--r-- | coverage/execfile.py | 3 | ||||
-rw-r--r-- | test/test_process.py | 11 | ||||
-rw-r--r-- | test/try_execfile.py | 7 |
3 files changed, 14 insertions, 7 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index 1c0048ff..3283a3f7 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -83,7 +83,8 @@ def run_python_file(filename, args, package=None): main_mod = imp.new_module('__main__') sys.modules['__main__'] = main_mod main_mod.__file__ = filename - main_mod.__package__ = package + if package: + main_mod.__package__ = package main_mod.__builtins__ = BUILTINS # Set sys.argv and the first path element properly. diff --git a/test/test_process.py b/test/test_process.py index 085ac130..b40eac12 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -279,11 +279,12 @@ class ProcessTest(CoverageTest): out2 = self.run_command("python run_me.py") self.assertMultiLineEqual(out, out2) - def test_coverage_run_dashm_is_like_python_dashm(self): - # These -m commands assume the coverage tree is on the path. - out = self.run_command("coverage run -m test.try_execfile") - out2 = self.run_command("python -m test.try_execfile") - self.assertMultiLineEqual(out, out2) + if sys.version_info >= (2, 6): # Doesn't work in 2.5, and I don't care! + def test_coverage_run_dashm_is_like_python_dashm(self): + # These -m commands assume the coverage tree is on the path. + out = self.run_command("coverage run -m test.try_execfile") + out2 = self.run_command("python -m test.try_execfile") + self.assertMultiLineEqual(out, out2) if hasattr(os, 'fork'): def test_fork(self): diff --git a/test/try_execfile.py b/test/try_execfile.py index 825fdb70..9bbabd1a 100644 --- a/test/try_execfile.py +++ b/test/try_execfile.py @@ -12,13 +12,18 @@ def my_function(a): FN_VAL = my_function("fooey") +try: + pkg = __package__ +except NameError: + pkg = "*No __package__*" + globals_to_check = { '__name__': __name__, '__file__': __file__, '__doc__': __doc__, '__builtins__.has_open': hasattr(__builtins__, 'open'), '__builtins__.dir': dir(__builtins__), - '__package__': __package__, + '__package__': pkg, 'DATA': DATA, 'FN_VAL': FN_VAL, '__main__.DATA': getattr(__main__, "DATA", "nothing"), |