ApprovalTests.Python icon indicating copy to clipboard operation
ApprovalTests.Python copied to clipboard

create_directory_if_needed race condition

Open apmorton opened this issue 1 year ago • 0 comments

approvaltests/file_approver.py:54: in verify
    received = writer.write_received_file(received)
approvaltests/string_writer.py:33: in write_received_file
    create_directory_if_needed(received_file)
approval_utilities/utils.py:69: in create_directory_if_needed
    os.makedirs(directory)
<frozen os>:225: in makedirs
    ???
E   FileExistsError: [Errno 17] File exists: '/some/directory/here'

If multiple tests are running in parallel and attempting to write different files in the same directory they may race to create the directory and fail.

create_directory_if_needed should not check for existence and conditionally call os.makedirs, it should call os.makedirs(path, exist_ok=True) unconditionally.

apmorton avatar Jul 24 '24 21:07 apmorton