Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in

Unified Diff: Lib/test/test_site.py

Issue 11591: "python -S" should be robust against e.g. "from site import addsitedir"
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_site.py
+++ b/Lib/test/test_site.py
@@ -11,18 +11,15 @@ import builtins
import os
import sys
import re
+import site
import encodings
import subprocess
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
- raise unittest.SkipTest("importation of site.py suppressed")
+skip_unless_user_site = unittest.skipUnless(
+ site.ENABLE_USER_SITE, 'user site-packages disabled by -s or -S')
if not os.path.isdir(site.USER_SITE):
# need to add user site directory for tests
@@ -159,7 +156,10 @@ class HelperFunctionsTests(unittest.Test
def test_s_option(self):
usersite = site.USER_SITE
- self.assertIn(usersite, sys.path)
+ self.assertIn(usersite, sys.path)
+ else:
+ self.assertNotIn(usersite, sys.path)
env = os.environ.copy()
rc = subprocess.call([sys.executable, '-c',
@@ -363,16 +363,19 @@ class ImportSideEffectTests(unittest.Tes
# XXX: implement
+ @skip_unless_user_site
def test_setting_quit(self):
# 'quit' and 'exit' should be injected into builtins
self.assertTrue(hasattr(builtins, "quit"))
self.assertTrue(hasattr(builtins, "exit"))
+ @skip_unless_user_site
def test_setting_copyright(self):
# 'copyright' and 'credits' should be in builtins
self.assertTrue(hasattr(builtins, "copyright"))
self.assertTrue(hasattr(builtins, "credits"))
+ @skip_unless_user_site
def test_setting_help(self):
# 'help' should be set in builtins
self.assertTrue(hasattr(builtins, "help"))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+