From ae512d2feee010e100d639d3e48473f96f96a38c Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Wed, 14 Mar 2018 23:10:41 +0800 Subject: [PATCH 1/2] chdir when testing .env loading Fix #1666. This also fixes the .env overwriting so we can get rid of the recovering fixture! --- tests/test_pipenv.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 055eb7d0..3dd77eee 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -20,7 +20,7 @@ if PY2: try: from pathlib import Path -except: +except ImportError: from pipenv.vendor.pathlib2 import Path os.environ['PIPENV_DONT_USE_PYENV'] = '1' @@ -34,25 +34,10 @@ def pip_src_dir(request): old_src_dir = os.environ.get('PIP_SRC', '') new_src_dir = TemporaryDirectory(prefix='pipenv-', suffix='-testsrc') os.environ['PIP_SRC'] = new_src_dir.name + def finalize(): new_src_dir.cleanup() os.environ['PIP_SRC'] = old_src_dir - request.addfinalizer(finalize) - return request - - -@pytest.fixture() -def backup_dotenv(request): - if os.path.exists('.env'): - with open('.env') as f: - prev_dotenv = f.read() - else: - prev_dotenv = None - - def finalize(): - if prev_dotenv is not None: - with open('.env', 'w') as f: - f.write(prev_dotenv) request.addfinalizer(finalize) return request @@ -712,10 +697,9 @@ requests = {version = "*"} @pytest.mark.run @pytest.mark.dotenv - @pytest.mark.usefixtures('backup_dotenv') def test_env(self): - with PipenvInstance(pipfile=False) as p: + with PipenvInstance(pipfile=False, chdir=True) as p: with open('.env', 'w') as f: f.write('HELLO=WORLD') From 4d41f918ac8a01e51b67494c3a66aab7b622ae7e Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 15 Mar 2018 00:50:21 +0800 Subject: [PATCH 2/2] Better testing basic outputs --- tests/test_pipenv.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 3dd77eee..5cb012c1 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -127,19 +127,22 @@ class TestPipenv: def test_pipenv_venv(self): with PipenvInstance() as p: p.pipenv('--python python') - assert p.pipenv('--venv').out + venv_path = p.pipenv('--venv').out.strip() + assert os.path.isdir(venv_path) @pytest.mark.cli def test_pipenv_py(self): with PipenvInstance() as p: p.pipenv('--python python') - assert p.pipenv('--py').out + python = p.pipenv('--py').out.strip() + assert os.path.basename(python).startswith('python') @pytest.mark.cli def test_pipenv_rm(self): with PipenvInstance() as p: p.pipenv('--python python') - venv_path = p.pipenv('--venv').out + venv_path = p.pipenv('--venv').out.strip() + assert os.path.isdir(venv_path) assert p.pipenv('--rm').out assert not os.path.isdir(venv_path)