New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues in py.path.local.make_numbered_dir() #3810

fabioz opened this Issue Aug 13, 2018 · 0 comments


None yet
2 participants

fabioz commented Aug 13, 2018


Python 2.7.12 (default, Sep 20 2016, 14:51:55) [MSC v.1600 64 bit (AMD64)] on win32
>>> import pytest
>>> pytest.__version__

I found a case where I had many files on the disk (which were always traversed) which were relying on py.path.local.make_numbered_dir().

One is that is that py.path.local was being passed a unicode on Python 2 and the API doesn't handle it properly (yet everything seems to work) and the other is that if the test generates one file with more than 256 chars in the path, the temp dir remains there forever.

The problem is with the API:

from py.path import local
local.make_numbered_dir(prefix=u'tmp-', rootdir=root_dir)

The main issue is that all fails were silent (i.e.: the old files removal didn't work and there was no acknowledgement of it because remove errors are completely swallowed -- and there were many files on my use case which were still traversed because it does a chmod first which traverses the tree -- in my case 1-2 seconds of my pytest startup were always here for any run I did).

Below is a test with the issues:

# coding: utf-8

def test_py_local_remove_unicode(tmpdir):
    import os.path
    import py
    import sys

    unicode_chars = 'áéíóú'
    path_with_unicode_chars = os.path.join(str(tmpdir), unicode_chars, unicode_chars)

    with open(os.path.join(path_with_unicode_chars, unicode_chars), 'w') as stream:

    path_as_unicode = os.path.dirname(path_with_unicode_chars).decode(sys.getfilesystemencoding())
    local_path = py.path.local(path_as_unicode)
    assert not os.path.exists(path_with_unicode_chars)


    with open("\\\\?\\" + os.path.join(path_with_unicode_chars, 'a' * 250), 'w') as stream:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment