From f730dd48996b06b4ff0a228564641a65a0682567 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 12 Apr 2018 17:48:04 +0800 Subject: [PATCH] Fix relative paths in tests --- tests/integration/conftest.py | 9 ++++++++- tests/integration/test_install_twists.py | 19 +++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 65601ddd..f94137b3 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -30,6 +30,8 @@ def check_internet(): WE_HAVE_INTERNET = check_internet() +TESTS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + def pytest_runtest_setup(item): if item.get_marker('needs_internet') is not None and not WE_HAVE_INTERNET: @@ -40,7 +42,7 @@ def pytest_sessionstart(session): os.environ['PIPENV_DONT_USE_PYENV'] = '1' os.environ['PIPENV_IGNORE_VIRTUALENVS'] = '1' os.environ['PIPENV_VENV_IN_PROJECT'] = '1' - os.environ['PYPI_VENDOR_DIR'] = os.path.join(os.path.dirname(__file__), 'pypi') + os.environ['PYPI_VENDOR_DIR'] = os.path.join(TESTS_ROOT, 'pypi') class _PipenvInstance(object): @@ -136,3 +138,8 @@ def pip_src_dir(request): request.addfinalizer(finalize) return request + + +@pytest.fixture() +def testsroot(): + return TESTS_ROOT diff --git a/tests/integration/test_install_twists.py b/tests/integration/test_install_twists.py index 2fdec67c..b4b78632 100644 --- a/tests/integration/test_install_twists.py +++ b/tests/integration/test_install_twists.py @@ -6,9 +6,7 @@ try: except ImportError: import pathlib2 as pathlib -from pipenv.utils import mkdir_p - -from pipenv.utils import temp_environ +from pipenv.utils import mkdir_p, temp_environ import pytest @@ -152,14 +150,13 @@ Requests = "==2.14.0" # Inline comment @pytest.mark.resolver @pytest.mark.eggs @flaky -def test_local_package(PipenvInstance, pip_src_dir, pypi): +def test_local_package(PipenvInstance, pip_src_dir, pypi, testsroot): """This test ensures that local packages (directories with a setup.py) installed in editable mode have their dependencies resolved as well""" file_name = 'tablib-0.12.1.tar.gz' package = 'tablib-0.12.1' # Not sure where travis/appveyor run tests from - test_dir = os.path.dirname(os.path.abspath(__file__)) - source_path = os.path.abspath(os.path.join(test_dir, 'test_artifacts', file_name)) + source_path = os.path.abspath(os.path.join(testsroot, 'test_artifacts', file_name)) with PipenvInstance(chdir=True, pypi=pypi) as p: # This tests for a bug when installing a zipfile in the current dir copy_to = os.path.join(p.path, file_name) @@ -174,11 +171,10 @@ def test_local_package(PipenvInstance, pip_src_dir, pypi): @pytest.mark.files @flaky -def test_local_zipfiles(PipenvInstance, pypi): +def test_local_zipfiles(PipenvInstance, pypi, testsroot): file_name = 'tablib-0.12.1.tar.gz' # Not sure where travis/appveyor run tests from - test_dir = os.path.dirname(os.path.abspath(__file__)) - source_path = os.path.abspath(os.path.join(test_dir, 'test_artifacts', file_name)) + source_path = os.path.abspath(os.path.join(testsroot, 'test_artifacts', file_name)) with PipenvInstance(chdir=True, pypi=pypi) as p: # This tests for a bug when installing a zipfile in the current dir @@ -200,10 +196,9 @@ def test_local_zipfiles(PipenvInstance, pypi): @pytest.mark.files @flaky -def test_relative_paths(PipenvInstance, pypi): +def test_relative_paths(PipenvInstance, pypi, testsroot): file_name = 'tablib-0.12.1.tar.gz' - test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__))) - source_path = os.path.abspath(os.path.join(test_dir, 'test_artifacts', file_name)) + source_path = os.path.abspath(os.path.join(testsroot, 'test_artifacts', file_name)) with PipenvInstance(pypi=pypi) as p: artifact_dir = 'artifacts'