Commits

Ralf Schmitt committed ee60235

run tests in their own __main__ module

do not use the current globals() as namespace, rather setup a clean
namespace inside a newly created __main__ module.

the missing "import sys" in test__socket_timeout.py fixed two commits
ago, wouldn't go unnoticed with this change.

  • Participants
  • Parent commits 6c7face

Comments (0)

Files changed (1)

File greentest/testrunner.py

     return os.path.join(os.path.dirname(tempnam), 'testresults.sqlite3')
 
 
+def execfile_as_main(path):
+    import __builtin__
+    oldmain = sys.modules["__main__"]
+    main = sys.__class__("__main__")
+    main.__file__ = path
+    main.__builtins__ = __builtin__
+    main.__package__ = None
+    try:
+        sys.modules["__main__"] = main
+        return execfile(path, main.__dict__)
+    finally:
+        sys.modules["__main__"] = oldmain
+
+
 def run_tests(options, args):
     arg = args[0]
     module_name = arg
         test_support.BasicTestRunner = _runner
 
     sys.argv = args
-    globals()['__file__'] = arg
 
     if os.path.exists(arg):
-        execfile(arg, globals())
+        execfile_as_main(arg)
     else:
         test = defaultTestLoader.loadTestsFromName(arg)
         result = _runner().run(test)