Skip to content

Commit e03253a

Browse files
committed
testing/conftest.py: add symlink_or_skip
Taken out of pytest-dev#6733, returning for existing symlink (should not skip).
1 parent 5478716 commit e03253a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

testing/conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,27 @@ def testdir(testdir: Testdir) -> Testdir:
165165
return testdir
166166

167167

168+
@pytest.fixture
169+
def symlink_or_skip():
170+
"""Return a function that creates a symlink or raises ``Skip``.
171+
172+
On Windows `os.symlink` is available, but normal users require special
173+
admin privileges to create symlinks.
174+
"""
175+
176+
def wrap_os_symlink(src, dst, *args, **kwargs):
177+
if os.path.islink(dst):
178+
return
179+
180+
try:
181+
os.symlink(src, dst, *args, **kwargs)
182+
except OSError as e:
183+
pytest.skip("os.symlink({!r}) failed: {!r}".format((src, dst), e))
184+
assert os.path.islink(dst)
185+
186+
return wrap_os_symlink
187+
188+
168189
@pytest.fixture(scope="session")
169190
def color_mapping():
170191
"""Returns a utility class which can replace keys in strings in the form "{NAME}"

0 commit comments

Comments
 (0)