[svn r62282] refine a test

--HG--
branch : trunk
This commit is contained in:
hpk 2009-03-01 09:00:20 +01:00
parent 1f70447dde
commit 9d9a94ce00
1 changed files with 4 additions and 12 deletions

View File

@ -162,7 +162,6 @@ class TestPyPlugins:
assert l == ["hellospecific", "helloanonymous"] assert l == ["hellospecific", "helloanonymous"]
def test_consider_env(self, monkeypatch): def test_consider_env(self, monkeypatch):
# XXX write a helper for preserving os.environ
plugins = PyPlugins() plugins = PyPlugins()
monkeypatch.setitem(os.environ, 'PYLIB', "unknownconsider_env") monkeypatch.setitem(os.environ, 'PYLIB', "unknownconsider_env")
py.test.raises(ImportError, "plugins.consider_env()") py.test.raises(ImportError, "plugins.consider_env()")
@ -185,25 +184,18 @@ class TestPyPlugins:
def test_api_and_defaults(): def test_api_and_defaults():
assert isinstance(py._com.pyplugins, PyPlugins) assert isinstance(py._com.pyplugins, PyPlugins)
def test_subprocess_env(): def test_subprocess_env(testdir, monkeypatch):
# XXX write a helper for preserving os.environ
plugins = PyPlugins() plugins = PyPlugins()
KEY = "PYLIB" old = py.path.local(py.__file__).dirpath().dirpath().chdir()
old = os.environ.get(KEY, None)
olddir = py.path.local(py.__file__).dirpath().dirpath().chdir()
try: try:
os.environ[KEY] = "unknownconsider_env" monkeypatch.setitem(os.environ, "PYLIB", 'unknownconsider')
excinfo = py.test.raises(py.process.cmdexec.Error, """ excinfo = py.test.raises(py.process.cmdexec.Error, """
py.process.cmdexec("python -c 'import py'") py.process.cmdexec("python -c 'import py'")
""") """)
assert str(excinfo.value).find("ImportError") != -1 assert str(excinfo.value).find("ImportError") != -1
assert str(excinfo.value).find("unknownconsider") != -1 assert str(excinfo.value).find("unknownconsider") != -1
finally: finally:
olddir.chdir() old.chdir()
if old is None:
del os.environ[KEY]
else:
os.environ[KEY] = old
class TestPyPluginsEvents: class TestPyPluginsEvents:
def test_pyevent_named_dispatch(self): def test_pyevent_named_dispatch(self):