summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2014-11-11 12:01:10 -0600
committerMichael Merickel <michael@merickel.org>2014-11-11 12:01:10 -0600
commit823ac447329e46e5826e8e3228d9f847f9790ee8 (patch)
tree217c0ca6d3ff00ef8c4e17688571898ea2e2f3a5
parentf3a5679992c51ed3067bb6f5b577dad9fe4274ff (diff)
downloadpyramid-823ac447329e46e5826e8e3228d9f847f9790ee8.tar.gz
pyramid-823ac447329e46e5826e8e3228d9f847f9790ee8.tar.bz2
pyramid-823ac447329e46e5826e8e3228d9f847f9790ee8.zip
adjust tests to work even when someone has defined PYTHONSTARTUP in their shell
-rw-r--r--CHANGES.txt2
-rw-r--r--pyramid/scripts/pshell.py3
-rw-r--r--pyramid/tests/test_scripts/test_pshell.py41
3 files changed, 20 insertions, 26 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 4bd438bd7..f72a793a5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -26,7 +26,7 @@ Features
- The ``pshell`` script will now load a ``PYTHONSTARTUP`` file if one is
defined in the environment prior to launching the interpreter.
- See https://github.com/Pylons/pyramid/pull/1299
+ See https://github.com/Pylons/pyramid/pull/1448
Bug Fixes
---------
diff --git a/pyramid/scripts/pshell.py b/pyramid/scripts/pshell.py
index ef462239b..1168ba78a 100644
--- a/pyramid/scripts/pshell.py
+++ b/pyramid/scripts/pshell.py
@@ -53,12 +53,11 @@ class PShellCommand(object):
loaded_objects = {}
object_help = {}
setup = None
- pystartup = None
+ pystartup = os.environ.get('PYTHONSTARTUP')
def __init__(self, argv, quiet=False):
self.quiet = quiet
self.options, self.args = self.parser.parse_args(argv[1:])
- self.pystartup = os.environ.get('PYTHONSTARTUP')
def pshell_file_config(self, filename):
config = self.ConfigParser()
diff --git a/pyramid/tests/test_scripts/test_pshell.py b/pyramid/tests/test_scripts/test_pshell.py
index 86858a709..a6ba2eaea 100644
--- a/pyramid/tests/test_scripts/test_pshell.py
+++ b/pyramid/tests/test_scripts/test_pshell.py
@@ -1,3 +1,4 @@
+import os
import unittest
from pyramid.tests.test_scripts import dummy
@@ -24,6 +25,9 @@ class TestPShellCommand(unittest.TestCase):
self.options.python_shell = ''
self.options.setup = None
cmd.options = self.options
+ # default to None to prevent side-effects from running tests in
+ # unknown environments
+ cmd.pystartup = None
return cmd
def test_make_default_shell(self):
@@ -370,33 +374,24 @@ class TestPShellCommand(unittest.TestCase):
self.assertTrue(shell.help)
def test_command_loads_pythonstartup(self):
- import os
- marker = object()
- old_pystartup = os.environ.get('PYTHONSTARTUP', marker)
- os.environ['PYTHONSTARTUP'] = (
+ command = self._makeOne()
+ command.pystartup = (
os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'pystartup.py')))
- try:
- command = self._makeOne()
- shell = dummy.DummyShell()
- command.run(shell)
- self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
- self.assertEqual(shell.env, {
- 'app':self.bootstrap.app, 'root':self.bootstrap.root,
- 'registry':self.bootstrap.registry,
- 'request':self.bootstrap.request,
- 'root_factory':self.bootstrap.root_factory,
- 'foo':1,
- })
- self.assertTrue(self.bootstrap.closer.called)
- self.assertTrue(shell.help)
- finally: # pragma: no cover
- if old_pystartup is not marker:
- os.environ['PYTHONSTARTUP'] = old_pystartup
- else:
- del os.environ['PYTHONSTARTUP']
+ shell = dummy.DummyShell()
+ command.run(shell)
+ self.assertEqual(self.bootstrap.a[0], '/foo/bar/myapp.ini#myapp')
+ self.assertEqual(shell.env, {
+ 'app':self.bootstrap.app, 'root':self.bootstrap.root,
+ 'registry':self.bootstrap.registry,
+ 'request':self.bootstrap.request,
+ 'root_factory':self.bootstrap.root_factory,
+ 'foo':1,
+ })
+ self.assertTrue(self.bootstrap.closer.called)
+ self.assertTrue(shell.help)
class Test_main(unittest.TestCase):
def _callFUT(self, argv):