Eryk Sun added the comment:
> def test_chdir():
> with tempfile.TemporaryDirectory() as tempdir:
> old = os.getcwd()
> os.chdir(tempdir)
> with open(os.path.join(tempdir, "delme")) as fout:
> fout.write("Hello")
> os.chdir(old)
The open() call in
Eryk Sun added the comment:
> Windows doesn't let you remove files and directories that are used
> by a process.
Windows does allow deleting open files/directories, but read/execute,
write/append, and delete/rename access have to be explicitly shared when
opening a file or directory. WinAP
Gabriele Tornetta added the comment:
That makes sense, but I wonder what the "right" behaviour should be in this
case. Surely the infinite recursion should be fixed at the very minimum.
Perhaps the code on Windows could be enhanced to catch the case whereby one is
trying to delete the cwd an
Christian Heimes added the comment:
The code fails because TemporaryDirectory.__exit__() is unable to remove the
directory. Windows doesn't let you remove files and directories that are used
by a process. On POSIX-like operating systems like Linux support removing of
opened files. For exampl
New submission from Gabriele Tornetta :
The following script causes havoc on Windows while it works as expected on
Linux
~~~ python
import os
import tempfile
def test_chdir():
with tempfile.TemporaryDirectory() as tempdir:
os.chdir(tempdir)
~~~
Running the above on Windows resu