Summary of changes
This PR is an approach to #1412 that adds a test to induce this race condition. The test relies on implementation details, but that is made explicit in the text of the test, I have done it this way because there isn't another great way to deterministically induce the problem.
Pull Request Checklist
This fixes a race condition in _bypass_ensure_directory where two threads or processes may erroneously fail because they are both creating the same directory. A more robust implementation of this may involve exposing the un-wrapped os.makedirs. Originally reported with proposed patch by @JonKohler in github PR #1412. This patch came out of discussions on that thread.