From 1dea2a27b2313bf9dcbeea7fb445e2765ee34c2e Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 12 Apr 2018 17:34:03 +0800 Subject: [PATCH] Project cannot be a fixture --- tests/conftest.py | 6 ------ tests/test_dot_venv.py | 5 +++-- tests/test_install_markers.py | 5 ++++- tests/test_pipenv.py | 5 +++-- tests/test_run.py | 6 +++++- tests/test_windows.py | 6 ++++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 5192d184..65601ddd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,7 +4,6 @@ import warnings import pytest -from pipenv.project import Project from pipenv.utils import TemporaryDirectory from pipenv.vendor import delegator from pipenv.vendor import requests @@ -137,8 +136,3 @@ def pip_src_dir(request): request.addfinalizer(finalize) return request - - -@pytest.fixture() -def project(): - return Project() diff --git a/tests/test_dot_venv.py b/tests/test_dot_venv.py index bb8a6607..0b4cb485 100644 --- a/tests/test_dot_venv.py +++ b/tests/test_dot_venv.py @@ -1,5 +1,6 @@ import os +from pipenv.project import Project from pipenv.utils import temp_environ, normalize_drive, get_windows_path from pipenv.vendor import delegator @@ -47,7 +48,7 @@ def test_reuse_previous_venv(PipenvInstance, pypi): @pytest.mark.windows @pytest.mark.pew @pytest.mark.skip('Not mocking this.') -def test_shell_nested_venv_in_project(PipenvInstance, pypi, project): +def test_shell_nested_venv_in_project(PipenvInstance, pypi): import subprocess with temp_environ(): os.environ['PIPENV_VENV_IN_PROJECT'] = '1' @@ -65,7 +66,7 @@ def test_shell_nested_venv_in_project(PipenvInstance, pypi, project): # Check for the venv directory c = delegator.run('pewtwo dir .venv') # Compare pew's virtualenv path to what we expect - venv_path = get_windows_path(project.project_directory, '.venv') + venv_path = get_windows_path(Project().project_directory, '.venv') # os.path.normpath will normalize slashes assert venv_path == normalize_drive(os.path.normpath(c.out.strip())) # Have pew run 'pip freeze' in the virtualenv diff --git a/tests/test_install_markers.py b/tests/test_install_markers.py index 16806cf7..9cc7446e 100644 --- a/tests/test_install_markers.py +++ b/tests/test_install_markers.py @@ -1,6 +1,7 @@ import os import sys +from pipenv.project import Project from pipenv.utils import temp_environ from pipenv.vendor import pipfile @@ -125,7 +126,7 @@ def test_resolver_unique_markers(PipenvInstance, pypi): @pytest.mark.project @flaky -def test_environment_variable_value_does_not_change_hash(PipenvInstance, pypi, project): +def test_environment_variable_value_does_not_change_hash(PipenvInstance, pypi): with PipenvInstance(chdir=True, pypi=pypi) as p: with temp_environ(): with open(p.pipfile_path, 'w') as f: @@ -139,6 +140,8 @@ python_version = '2.7' [packages] flask = "==0.12.2" """) + project = Project() + os.environ['PYPI_USERNAME'] = 'whatever' os.environ['PYPI_PASSWORD'] = 'pass' assert project.get_lockfile_hash() is None diff --git a/tests/test_pipenv.py b/tests/test_pipenv.py index 49d6055f..3d8a197b 100644 --- a/tests/test_pipenv.py +++ b/tests/test_pipenv.py @@ -4,6 +4,7 @@ XXX: Try our best to reduce tests in this file. """ from pipenv.core import activate_virtualenv +from pipenv.project import Project import pytest @@ -23,9 +24,9 @@ def test_code_import_manual(PipenvInstance): @pytest.mark.code @pytest.mark.virtualenv @pytest.mark.project -def test_activate_virtualenv_no_source(project): +def test_activate_virtualenv_no_source(): command = activate_virtualenv(source=False) - venv = project.virtualenv_location + venv = Project().virtualenv_location assert command == '{0}/bin/activate'.format(venv) diff --git a/tests/test_run.py b/tests/test_run.py index 30efb077..72f10596 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -1,5 +1,7 @@ import os +from pipenv.project import Project + import pytest @@ -16,7 +18,7 @@ def test_env(PipenvInstance): @pytest.mark.run -def test_scripts(PipenvInstance, project): +def test_scripts(PipenvInstance): with PipenvInstance(chdir=True) as p: with open(p.pipfile_path, 'w') as f: f.write(r""" @@ -41,6 +43,8 @@ multicommand = "bash -c \"cd docs && make html\"" assert 'Error' in c.err assert 'randomthingtotally (from notfoundscript)' in c.err + project = Project() + script = project.build_script('multicommand') assert script.command == 'bash' assert script.args == ['-c', 'cd docs && make html'] diff --git a/tests/test_windows.py b/tests/test_windows.py index 02ae4f32..7683bf80 100644 --- a/tests/test_windows.py +++ b/tests/test_windows.py @@ -1,5 +1,7 @@ import os +from pipenv.project import Project + import pytest @@ -8,14 +10,14 @@ pytestmark = pytest.mark.skipif(os.name == 'nt', reason="only relevant on window @pytest.mark.project -def test_case_changes_windows(PipenvInstance, pypi, project): +def test_case_changes_windows(PipenvInstance, pypi): """Test project matching for case changes on Windows. """ with PipenvInstance(pypi=pypi, chdir=True) as p: c = p.pipenv('install pytz') assert c.return_code == 0 - virtualenv_location = project.virtualenv_location + virtualenv_location = Project().virtualenv_location target = p.path.upper() if target == p.path: target = p.path.lower()