diff -r e961a166dc70 Lib/test/test_site.py --- a/Lib/test/test_site.py Tue Dec 10 22:16:41 2013 -0700 +++ b/Lib/test/test_site.py Wed Dec 11 15:10:11 2013 -0600 @@ -6,8 +6,7 @@ """ import unittest import test.support -from test.support import run_unittest, TESTFN, EnvironmentVarGuard -from test.support import captured_stderr +from test.support import captured_stderr, TESTFN, EnvironmentVarGuard import builtins import os import sys @@ -19,13 +18,14 @@ import sysconfig from copy import copy -# Need to make sure to not import 'site' if someone specified ``-S`` at the -# command-line. Detect this by just making sure 'site' has not been imported -# already. -if "site" in sys.modules: - import site -else: - raise unittest.SkipTest("importation of site.py suppressed") +# It is safe to import site regardless of sys.flags.no_site; site's side +# effects are restricted to site.main(), which is not executed if +# sys.flags.no_site is True. It's safer to not run the test if we were +# started with -S, though. +if sys.flags.no_site: + raise unittest.SkipTest("Python was invoked with -S") + +import site if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE): # need to add user site directory for tests