From aeb8a5c5d6f102cea16c0bd5ab7fd2f9d3f4a203 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Tue, 12 Mar 2013 15:32:27 -0400 Subject: [PATCH] Improved test cleanup for environment-variable-based configuration. --- pecan/tests/test_conf.py | 10 +++++----- setup.py | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pecan/tests/test_conf.py b/pecan/tests/test_conf.py index f063faf..36ce380 100644 --- a/pecan/tests/test_conf.py +++ b/pecan/tests/test_conf.py @@ -3,6 +3,8 @@ import sys from pecan.tests import PecanTestCase +from mock import patch + __here__ = os.path.dirname(__file__) @@ -294,7 +296,6 @@ class TestConfFromEnv(PecanTestCase): def setUp(self): super(TestConfFromEnv, self).setUp() self.conf_from_env = self.get_conf_from_env() - os.environ['PECAN_CONFIG'] = '' def tearDown(self): os.environ['PECAN_CONFIG'] = '' @@ -311,8 +312,8 @@ class TestConfFromEnv(PecanTestCase): assert issubclass(exc, error.__class__) assert error.message == msg + @patch.dict('os.environ', {'PECAN_CONFIG': '/'}) def test_invalid_path(self): - os.environ['PECAN_CONFIG'] = '/' msg = "PECAN_CONFIG was set to an invalid path: /" self.assertRaisesMessage(msg, RuntimeError, self.conf_from_env) @@ -321,7 +322,6 @@ class TestConfFromEnv(PecanTestCase): "no config file was passed as an argument." self.assertRaisesMessage(msg, RuntimeError, self.conf_from_env) + @patch.dict('os.environ', {'PECAN_CONFIG': os.path.abspath(__file__)}) def test_return_valid_path(self): - here = os.path.abspath(__file__) - os.environ['PECAN_CONFIG'] = here - assert self.conf_from_env() == here + assert self.conf_from_env() == os.path.abspath(__file__) diff --git a/setup.py b/setup.py index 46a677d..fe862d1 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,8 @@ tests_require = requirements + [ 'Genshi', 'Kajiki', 'Jinja2', - 'gunicorn' + 'gunicorn', + 'mock' ] if sys.version_info < (2, 7): tests_require += ['unittest2']