LocalPath.mkdir: No recursive directory creation when using mkdir
pytestbot opened this issue · comments
- Bitbucket: https://bitbucket.org/pytest-dev/py/issue/79
- Originally reported by: @eka
- Originally created at: 2016-04-28T15:06:17.320
When trying to create a recursive directory I have to call to LocalPath.mkdir N times the level of directories I want to create creating intermediate LocalPath instances.
Also I'm lost at what is the use that LocalPath.mkdir will join all the args passed if it can't create recursive directories. (bug?)
Could be good that LocalPath.mkdir internally uses os.makedirs instead or for LocalPath to provide LocalPath.makedirs method.
Thanks
Original comment by @eka
@b-enlnt thanks didn't know about that and it wasn't at all intuitive, but will try it.
Original comment by @sashkab
Why can't you use path.ensure(dir=True)
to make whole directory three? At least it works for me.
Example:
path = py.path.local('/tmp/xxx/xxx/zzz/one/doesnt/exist'.ensure(dir=True)
It will create directories required. dir=True
will ensure that exists
is a directory, not a file.
closing as works as intended - ensure is for recursive, mkdir is for no-surprise fail early on mistakes