python-click/tests/conftest.py

32 lines
794 B
Python
Raw Normal View History

2021-10-10 03:31:57 +02:00
import os
import shutil
import tempfile
2014-10-16 20:40:34 +02:00
import pytest
2020-07-21 08:23:42 +02:00
from click.testing import CliRunner
2014-10-16 20:40:34 +02:00
2020-07-21 08:23:42 +02:00
@pytest.fixture(scope="function")
2014-10-16 20:40:34 +02:00
def runner(request):
return CliRunner()
2021-10-10 03:31:57 +02:00
def check_symlink_impl():
"""This function checks if using symlinks is allowed
on the host machine"""
tempdir = tempfile.mkdtemp(prefix="click-")
test_pth = os.path.join(tempdir, "check_sym_impl")
sym_pth = os.path.join(tempdir, "link")
open(test_pth, "w").close()
rv = True
try:
os.symlink(test_pth, sym_pth)
except (NotImplementedError, OSError):
# Creating symlinks on Windows require elevated access.
# OSError is thrown if the function is called without it.
rv = False
finally:
shutil.rmtree(tempdir, ignore_errors=True)
return rv