Closed
Conversation
nicoddemus
commented
Jul 8, 2022
| os.close(fd) | ||
|
|
||
| def _replace_atomic(src, dst): | ||
| os.rename(src, dst) |
Member
Author
There was a problem hiding this comment.
I did try to replace this call with os.replace and using this implementation on windows (as suggested in #10114 (comment)), however I get test failures:
λ pytest testing\test_atomic_writes.py
======================== test session starts ========================
platform win32 -- Python 3.9.8, pytest-7.2.0.dev91+g1689b3886.d20220613, pluggy-1.0.0
rootdir: e:\projects\pytest, configfile: pyproject.toml
plugins: hypothesis-6.34.1, flake8-1.0.7, flakes-4.0.5
collected 6 items
testing\test_atomic_writes.py F.F..F [100%]
============================= FAILURES ==============================
_________________________ test_atomic_write _________________________
tmp_path = WindowsPath('E:/.tmp/pytest-of-Pichau/pytest-3049/test_atomic_write0')
def test_atomic_write(tmp_path: Path) -> None:
fname = tmp_path.joinpath("ha")
for i in range(2):
with atomic_write(str(fname), overwrite=True) as f:
> f.write("hoho")
testing\test_atomic_writes.py:19:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Python39\lib\contextlib.py:126: in __exit__
next(self.gen)
src\_pytest\atomic_writes.py:146: in _open
self.commit(f)
src\_pytest\atomic_writes.py:181: in commit
replace_atomic(f.name, self._path)
src\_pytest\atomic_writes.py:80: in replace_atomic
return _replace_atomic(src, dst)
src\_pytest\atomic_writes.py:36: in _replace_atomic
_sync_directory(os.path.normpath(os.path.dirname(dst)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
directory = 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_atomic_write0'
def _sync_directory(directory):
# Ensure that filenames are written to disk
> fd = os.open(directory, 0)
E PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_atomic_write0'
src\_pytest\atomic_writes.py:28: PermissionError
_____________ test_replace_simultaneously_created_file ______________
tmp_path = WindowsPath('E:/.tmp/pytest-of-Pichau/pytest-3049/test_replace_simultaneously_cr0')
def test_replace_simultaneously_created_file(tmp_path: Path) -> None:
fname = tmp_path.joinpath("ha")
with atomic_write(str(fname), overwrite=True) as f:
f.write("hoho")
fname.write_text("harhar")
> assert fname.read_text() == "harhar"
testing\test_atomic_writes.py:45:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Python39\lib\contextlib.py:126: in __exit__
next(self.gen)
src\_pytest\atomic_writes.py:146: in _open
self.commit(f)
src\_pytest\atomic_writes.py:181: in commit
replace_atomic(f.name, self._path)
src\_pytest\atomic_writes.py:80: in replace_atomic
return _replace_atomic(src, dst)
src\_pytest\atomic_writes.py:36: in _replace_atomic
_sync_directory(os.path.normpath(os.path.dirname(dst)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
directory = 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_replace_simultaneously_cr0'
def _sync_directory(directory):
# Ensure that filenames are written to disk
> fd = os.open(directory, 0)
E PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_replace_simultaneously_cr0'
src\_pytest\atomic_writes.py:28: PermissionError
_____________________ test_atomic_write_in_pwd ______________________
tmp_path = WindowsPath('E:/.tmp/pytest-of-Pichau/pytest-3049/test_atomic_write_in_pwd0')
def test_atomic_write_in_pwd(tmp_path: Path) -> None:
orig_curdir = os.getcwd()
try:
os.chdir(str(tmp_path))
fname = "ha"
for i in range(2):
with atomic_write(str(fname), overwrite=True) as f:
> f.write("hoho")
testing\test_atomic_writes.py:86:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Python39\lib\contextlib.py:126: in __exit__
next(self.gen)
src\_pytest\atomic_writes.py:146: in _open
self.commit(f)
src\_pytest\atomic_writes.py:181: in commit
replace_atomic(f.name, self._path)
src\_pytest\atomic_writes.py:80: in replace_atomic
return _replace_atomic(src, dst)
src\_pytest\atomic_writes.py:36: in _replace_atomic
_sync_directory(os.path.normpath(os.path.dirname(dst)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
directory = '.'
def _sync_directory(directory):
# Ensure that filenames are written to disk
> fd = os.open(directory, 0)
E PermissionError: [Errno 13] Permission denied: '.'
src\_pytest\atomic_writes.py:28: PermissionError
====================== short test summary info ======================
FAILED testing/test_atomic_writes.py::test_atomic_write - PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-...
FAILED testing/test_atomic_writes.py::test_replace_simultaneously_created_file - PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-...
FAILED testing/test_atomic_writes.py::test_atomic_write_in_pwd - PermissionError: [Errno 13] Permission denied: '.'
==================== 3 failed, 3 passed in 0.20s ====================
Decided to leave this as is instead of investigating further, but suggestions are welcome.
Member
Member
Author
|
Argh no I didn't! |
Member
Author
|
Closing in favor of #10115 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I took care of adding the files unchanged in the first commit, so we can track the exact changes that were done.
Closes #10114