Commit af57f15c by Brian Turek Committed by Bryce Drennan

Fix pytest fixtures on Win10 (#1326)

Catch and deal with failed symlinking on Windows
parent bd5fcf9b
...@@ -87,8 +87,16 @@ def mock_download(self, url, dest): ...@@ -87,8 +87,16 @@ def mock_download(self, url, dest):
if dest.exists(): if dest.exists():
os.unlink(str(dest)) os.unlink(str(dest))
if PY2 and WINDOWS: # Python2 does not support os.symlink on Windows whereas Python3 does. os.symlink requires either administrative
shutil.copyfile(str(fixture), str(dest)) # privileges or developer mode on Win10, throwing an OSError is neither is active.
if WINDOWS:
if PY2:
shutil.copyfile(str(fixture), str(dest))
else:
try:
os.symlink(str(fixture), str(dest))
except OSError:
shutil.copyfile(str(fixture), str(dest))
else: else:
os.symlink(str(fixture), str(dest)) os.symlink(str(fixture), str(dest))
......
...@@ -52,8 +52,16 @@ def mock_download(self, url, dest): ...@@ -52,8 +52,16 @@ def mock_download(self, url, dest):
if dest.exists(): if dest.exists():
shutil.rmtree(str(dest)) shutil.rmtree(str(dest))
if PY2 and WINDOWS: # Python2 does not support os.symlink on Windows whereas Python3 does. os.symlink requires either administrative
shutil.copyfile(str(fixture), str(dest)) # privileges or developer mode on Win10, throwing an OSError is neither is active.
if WINDOWS:
if PY2:
shutil.copyfile(str(fixture), str(dest))
else:
try:
os.symlink(str(fixture), str(dest))
except OSError:
shutil.copyfile(str(fixture), str(dest))
else: else:
os.symlink(str(fixture), str(dest)) os.symlink(str(fixture), str(dest))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment