pythonfinder
pythonfinder copied to clipboard
Tests failing on some filesystems
Hello, when I ran tox on my machine I got OSError [Errno 18] Invalid cross-device link at these tests:
- tests/test_python.py::test_python_versions
- tests/test_python.py::test_shims_are_kept
- tests/test_python.py::test_shims_are_removed
I think it is because my system uses different filesystem for /tmp directory, so when setup_pythons function in confest.py makes hard link, it fails. I wanted to ask if this issue is worth fixing.
I can possibly workaround that by editing tox.ini with this option of the pytest --basetemp=mydir.
The output of the test:
platform linux -- Python 3.7.2, pytest-4.4.0, py-1.8.0, pluggy-0.9.0 cachedir: .tox/py37/.pytest_cache rootdir: /home/pkopkan/Documents/rpm/python-pythonfinder/work_on_test/pythonfinder-1.2.0, inifile: setup.cfg, testpaths: tests/ plugins: timeout-1.3.3, cov-2.6.1 timeout: 300.0s timeout method: signal timeout func_only: False collected 47 itemstests/test_python.py E.....EE [ 17%] tests/test_utils.py ....................................... [100%]
==================================== ERRORS ==================================== ____________________ ERROR at setup of test_python_versions ____________________
tmpdir = local('/tmp/pytest-of-pkopkan/pytest-4/test_python_versions0')
@pytest.fixture
def special_character_python(tmpdir):
finder = pythonfinder.Finder(
global_search=True, system=False, ignore_unsupported=True
)
python = finder.find_python_version("2")
python_name = "{0}+".format(python.name)
python_folder = tmpdir.mkdir(python_name)
bin_dir = python_folder.mkdir("bin")
python_path = bin_dir.join("python")
os.link(python.path.as_posix(), python_path.strpath)
E OSError: [Errno 18] Invalid cross-device link: '/usr/bin/python2.7' -> '/tmp/pytest-of-pkopkan/pytest-4/test_python_versions0/python2.7+/bin/python'
tests/conftest.py:242: OSError ____________________ ERROR at setup of test_shims_are_kept _____________________
tmpdir = local('/tmp/pytest-of-pkopkan/pytest-4/test_shims_are_kept0')
@pytest.fixture
def setup_pythons(tmpdir):
runner = click.testing.CliRunner()
fake_root_path = tmpdir.join("root")
fake_root_path.mkdir()
fake_root = fake_root_path.strpath
with runner.isolated_filesystem(), vistir.contextmanagers.temp_environ():
home_dir = pythonfinder.utils.normalize_path(os.curdir)
# This is pip's isolation approach, swipe it for now for time savings
if sys.platform == "win32":
home_drive, home_path = os.path.splitdrive(home_dir)
os.environ.update(
{
"USERPROFILE": home_dir,
"HOMEDRIVE": home_drive,
"HOMEPATH": home_path,
}
)
for env_var, sub_path in (
("APPDATA", "AppData/Roaming"),
("LOCALAPPDATA", "AppData/Local"),
):
path = os.path.join(home_dir, *sub_path.split("/"))
os.environ[env_var] = path
vistir.path.mkdir_p(path)
else:
os.environ["HOME"] = home_dir
os.environ["XDG_DATA_HOME"] = os.path.join(home_dir, ".local", "share")
os.environ["XDG_CONFIG_HOME"] = os.path.join(home_dir, ".config")
os.environ["XDG_CACHE_HOME"] = os.path.join(home_dir, ".cache")
os.environ["XDG_RUNTIME_DIR"] = os.path.join(home_dir, ".runtime")
vistir.path.mkdir_p(os.path.join(home_dir, ".cache"))
vistir.path.mkdir_p(os.path.join(home_dir, ".config"))
vistir.path.mkdir_p(os.path.join(home_dir, ".local", "share"))
vistir.path.mkdir_p(os.path.join(fake_root, "usr", "local", "share"))
vistir.path.mkdir_p(os.path.join(fake_root, "usr", "share"))
os.environ["XDG_DATA_DIRS"] = ":".join(
[
os.path.join(fake_root, "usr", "local", "share"),
os.path.join(fake_root, "usr", "share"),
]
)
pyenv_dir = os.path.join(home_dir, ".pyenv")
asdf_dir = os.path.join(home_dir, ".asdf")
pyenv_shim_dir = os.path.join(pyenv_dir, "shims")
asdf_shim_dir = os.path.join(asdf_dir, "shims")
vistir.path.mkdir_p(pyenv_shim_dir)
vistir.path.mkdir_p(asdf_shim_dir)
env_path = os.pathsep.join([pyenv_shim_dir, asdf_shim_dir, os.defpath])
os.environ["PATH"] = env_path
all_versions = {}
for python in itertools.chain(
STACKLESS,
PYPY,
PYSTON,
MINICONDA,
MICROPYTHON,
JYTHON,
ANACONDA,
IRONPYTHON,
ACTIVEPYTHON,
PYTHON,
):
pyenv_bin = os.path.join(pyenv_dir, "versions", python, "bin")
asdf_bin = os.path.join(asdf_dir, "installs", "python", python, "bin")
vistir.path.mkdir_p(pyenv_bin)
vistir.path.mkdir_p(asdf_bin)
python_version = random.choice(["python3.7m", "python3.6m", "python2.7"])
all_versions[python] = os.path.join(pyenv_bin, python_version)
for exe in ["python", python_version, python]:
os.link(sys.executable, os.path.join(pyenv_bin, exe))
E OSError: [Errno 18] Invalid cross-device link: '/home/pkopkan/Documents/rpm/python-pythonfinder/work_on_test/pythonfinder-1.2.0/.tox/py37/bin/python' -> '/tmp/tmpgi7vwy2f/.pyenv/versions/stackless-dev/bin/python'
tests/conftest.py:215: OSError ___________________ ERROR at setup of test_shims_are_removed ___________________
tmpdir = local('/tmp/pytest-of-pkopkan/pytest-4/test_shims_are_removed0')
@pytest.fixture
def setup_pythons(tmpdir):
runner = click.testing.CliRunner()
fake_root_path = tmpdir.join("root")
fake_root_path.mkdir()
fake_root = fake_root_path.strpath
with runner.isolated_filesystem(), vistir.contextmanagers.temp_environ():
home_dir = pythonfinder.utils.normalize_path(os.curdir)
# This is pip's isolation approach, swipe it for now for time savings
if sys.platform == "win32":
home_drive, home_path = os.path.splitdrive(home_dir)
os.environ.update(
{
"USERPROFILE": home_dir,
"HOMEDRIVE": home_drive,
"HOMEPATH": home_path,
}
)
for env_var, sub_path in (
("APPDATA", "AppData/Roaming"),
("LOCALAPPDATA", "AppData/Local"),
):
path = os.path.join(home_dir, *sub_path.split("/"))
os.environ[env_var] = path
vistir.path.mkdir_p(path)
else:
os.environ["HOME"] = home_dir
os.environ["XDG_DATA_HOME"] = os.path.join(home_dir, ".local", "share")
os.environ["XDG_CONFIG_HOME"] = os.path.join(home_dir, ".config")
os.environ["XDG_CACHE_HOME"] = os.path.join(home_dir, ".cache")
os.environ["XDG_RUNTIME_DIR"] = os.path.join(home_dir, ".runtime")
vistir.path.mkdir_p(os.path.join(home_dir, ".cache"))
vistir.path.mkdir_p(os.path.join(home_dir, ".config"))
vistir.path.mkdir_p(os.path.join(home_dir, ".local", "share"))
vistir.path.mkdir_p(os.path.join(fake_root, "usr", "local", "share"))
vistir.path.mkdir_p(os.path.join(fake_root, "usr", "share"))
os.environ["XDG_DATA_DIRS"] = ":".join(
[
os.path.join(fake_root, "usr", "local", "share"),
os.path.join(fake_root, "usr", "share"),
]
)
pyenv_dir = os.path.join(home_dir, ".pyenv")
asdf_dir = os.path.join(home_dir, ".asdf")
pyenv_shim_dir = os.path.join(pyenv_dir, "shims")
asdf_shim_dir = os.path.join(asdf_dir, "shims")
vistir.path.mkdir_p(pyenv_shim_dir)
vistir.path.mkdir_p(asdf_shim_dir)
env_path = os.pathsep.join([pyenv_shim_dir, asdf_shim_dir, os.defpath])
os.environ["PATH"] = env_path
all_versions = {}
for python in itertools.chain(
STACKLESS,
PYPY,
PYSTON,
MINICONDA,
MICROPYTHON,
JYTHON,
ANACONDA,
IRONPYTHON,
ACTIVEPYTHON,
PYTHON,
):
pyenv_bin = os.path.join(pyenv_dir, "versions", python, "bin")
asdf_bin = os.path.join(asdf_dir, "installs", "python", python, "bin")
vistir.path.mkdir_p(pyenv_bin)
vistir.path.mkdir_p(asdf_bin)
python_version = random.choice(["python3.7m", "python3.6m", "python2.7"])
all_versions[python] = os.path.join(pyenv_bin, python_version)
for exe in ["python", python_version, python]:
os.link(sys.executable, os.path.join(pyenv_bin, exe))
E OSError: [Errno 18] Invalid cross-device link: '/home/pkopkan/Documents/rpm/python-pythonfinder/work_on_test/pythonfinder-1.2.0/.tox/py37/bin/python' -> '/tmp/tmpeq3v8sot/.pyenv/versions/stackless-dev/bin/python'
tests/conftest.py:215: OSError =========================== short test summary info ============================ ERROR tests/test_python.py::test_python_versions ERROR tests/test_python.py::test_shims_are_kept ERROR tests/test_python.py::test_shims_are_removed ====================== 44 passed, 3 error in 0.97 seconds ====================== ERROR: InvocationError for command '/home/pkopkan/Documents/rpm/python-pythonfinder/work_on_test/pythonfinder-1.2.0/.tox/py37/bin/coverage run -m pytest' (exited with code 1) ___________________________________ summary ____________________________________ ERROR: py37: commands failed
the tests currently rely either symlinks or hardlinks depending on the OS in question, and that is unfortunately not about to change as the alternative is to install pyenv
This is not something I plan to work on anytime in the future so feel free to PR A fix if you want