[lang-ref] ( move_file_to_directory ) ( python )
def test_move_file_to_directory(pushd):
# shutil.move(b, a)
import shutil
os.mkdir('dir1')
p = Path('file1.txt')
p.touch()
assert os.path.isfile('file1.txt')
with pytest.raises(IsADirectoryError):
os.rename('file1.txt', 'dir1/') # This fails (may be environment-dependent).
assert os.path.isfile('file1.txt')
assert not os.path.isfile('dir1/file1.txt')
shutil.move('file1.txt', 'dir1/') # This succeeds (shutil.move to directory is supported)
assert not os.path.isfile('file1.txt')
assert os.path.isfile('dir1/file1.txt')