Skip to content

Commit e43a2f7

Browse files
committed
Add test_symlink_or_skip
1 parent 1e5f692 commit e43a2f7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

testing/test_own_conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
3+
import pytest
4+
5+
6+
def test_symlink_or_skip(monkeypatch, tmpdir, symlink_or_skip):
7+
symlink_or_skip("src", "dst")
8+
assert os.path.islink("dst")
9+
10+
def oserror(src, dst):
11+
raise OSError("foo")
12+
13+
monkeypatch.setattr("os.symlink", oserror)
14+
15+
# Works with existing symlinks.
16+
symlink_or_skip("src", "dst")
17+
18+
with pytest.raises(
19+
pytest.skip.Exception,
20+
match=r"os\.symlink\(\('src', 'dst2'\)\) failed: OSError\('foo',?\)",
21+
):
22+
symlink_or_skip("src", "dst2")

0 commit comments

Comments
 (0)