Skip to content

Commit cc335d4

Browse files
fix #4179 - bring back the current testrun symlink
1 parent 93bdbf7 commit cc335d4

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

changelog/4179.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restore the tmpdir behaviour of symlinking the current test run.

src/_pytest/pathlib.py

+21
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ def _max(iterable, default):
100100
_max = max
101101

102102

103+
def _force_symlink(root, target, link_to):
104+
"""helper to create the current symlink
105+
106+
its full of race conditions that are reasonably ok to ignore
107+
for the contex of best effort linking to the latest testrun
108+
109+
the presumption being thatin case of much parallelism
110+
the inaccuracy is going to be acceptable
111+
"""
112+
current_symlink = root.joinpath(target)
113+
try:
114+
current_symlink.unlink()
115+
except OSError:
116+
pass
117+
try:
118+
current_symlink.symlink_to(link_to)
119+
except Exception:
120+
pass
121+
122+
103123
def make_numbered_dir(root, prefix):
104124
"""create a directory with a increased number as suffix for the given prefix"""
105125
for i in range(10):
@@ -112,6 +132,7 @@ def make_numbered_dir(root, prefix):
112132
except Exception:
113133
pass
114134
else:
135+
_force_symlink(root, prefix + "current", new_path)
115136
return new_path
116137
else:
117138
raise EnvironmentError(

testing/test_tmpdir.py

+4
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ def test_make(self, tmp_path):
196196
assert d.name.startswith(self.PREFIX)
197197
assert d.name.endswith(str(i))
198198

199+
symlink = tmp_path.joinpath(self.PREFIX + "current")
200+
assert symlink.is_symlink()
201+
assert symlink.resolve() == d.resolve()
202+
199203
def test_cleanup_lock_create(self, tmp_path):
200204
d = tmp_path.joinpath("test")
201205
d.mkdir()

0 commit comments

Comments
 (0)