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.

Comments (0)

Files changed (1)

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.