pytest-dev / pytest-dev/pytest

TestLocalPath.test_chdir_gone fails on OpenIndiana

Open
#11,402 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type: selftests
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

________________________ TestLocalPath.test_chdir_gone _________________________

self = <module 'py.error'>, func = <function rmtree at 0x7fffaea92af0>
args = ('/tmp/pytest-of-marcel/pytest-43/path1/dir_to_be_removed',)
kwargs = {'ignore_errors': False}, __tracebackhide__ = False
cls = <class 'py.error.EINVAL'>, value = OSError(22, 'Invalid argument')
tb = <traceback object at 0x7fffa9e9f3c0>, errno = 22

    def checked_call(self, func, *args, **kwargs):
        """ call a function and raise an errno-exception if applicable. """
        __tracebackhide__ = True
        try:
>           return func(*args, **kwargs)

/usr/lib/python3.9/vendor-packages/py/_error.py:66:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.9/shutil.py:740: in rmtree
    onerror(os.rmdir, path, sys.exc_info())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

path = '/tmp/pytest-of-marcel/pytest-43/path1/dir_to_be_removed'
ignore_errors = False
onerror = <function rmtree.<locals>.onerror at 0x7fffa94e2f70>

    def rmtree(path, ignore_errors=False, onerror=None):
        """Recursively delete a directory tree.

        If ignore_errors is set, errors are ignored; otherwise, if onerror
        is set, it is called to handle the error with arguments (func,
        path, exc_info) where func is platform and implementation dependent;
        path is the argument to that function that caused it to fail; and
        exc_info is a tuple returned by sys.exc_info().  If ignore_errors
        is false and onerror is None, an exception is raised.

        """
        sys.audit("shutil.rmtree", path)
        if ignore_errors:
            def onerror(*args):
                pass
        elif onerror is None:
            def onerror(*args):
                raise
        if _use_fd_functions:
            # While the unsafe rmtree works fine on bytes, the fd based does not.
            if isinstance(path, bytes):
                path = os.fsdecode(path)
            # Note: To guard against symlink races, we use the standard
            # lstat()/open()/fstat() trick.
            try:
                orig_st = os.lstat(path)
            except Exception:
                onerror(os.lstat, path, sys.exc_info())
                return
            try:
                fd = os.open(path, os.O_RDONLY)
                fd_closed = False
            except Exception:
                onerror(os.open, path, sys.exc_info())
                return
            try:
                if os.path.samestat(orig_st, os.fstat(fd)):
                    _rmtree_safe_fd(fd, path, onerror)
                    try:
                        os.close(fd)
                        fd_closed = True
>                       os.rmdir(path)
E                       OSError: [Errno 22] Invalid argument: '/tmp/pytest-of-marcel/pytest-43/path1/dir_to_be_removed'

/usr/lib/python3.9/shutil.py:738: OSError

During handling of the above exception, another exception occurred:

self = <test_local.TestLocalPath object at 0x7fffaa830520>
path1 = local('/tmp/pytest-of-marcel/pytest-43/path1')

    @skiponwin32
    def test_chdir_gone(self, path1):
        p = path1.ensure("dir_to_be_removed", dir=1)
        p.chdir()
>       p.remove()

$(BUILD_DIR)/testing/_py/test_local.py:623:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.9/vendor-packages/py/_path/local.py:218: in remove
    py.error.checked_call(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <module 'py.error'>, func = <function rmtree at 0x7fffaea92af0>
args = ('/tmp/pytest-of-marcel/pytest-43/path1/dir_to_be_removed',)
kwargs = {'ignore_errors': False}, __tracebackhide__ = False
cls = <class 'py.error.EINVAL'>, value = OSError(22, 'Invalid argument')
tb = <traceback object at 0x7fffa9e9f3c0>, errno = 22

    def checked_call(self, func, *args, **kwargs):
        """ call a function and raise an errno-exception if applicable. """
        __tracebackhide__ = True
        try:
            return func(*args, **kwargs)
        except self.Error:
            raise
        except (OSError, EnvironmentError):
            cls, value, tb = sys.exc_info()
            if not hasattr(value, 'errno'):
                raise
            __tracebackhide__ = False
            errno = value.errno
            try:
                if not isinstance(value, WindowsError):
                    raise NameError
            except NameError:
                # we are not on Windows, or we got a proper OSError
                cls = self._geterrnoclass(errno)
            else:
                try:
                    cls = self._geterrnoclass(_winerrnomap[errno])
                except KeyError:
                    raise value
>           raise cls("%s%r" % (func.__name__, args))
E           py.error.EINVAL: [Invalid argument]: rmtree('/tmp/pytest-of-marcel/pytest-43/path1/dir_to_be_removed',)

/usr/lib/python3.9/vendor-packages/py/_error.py:86: EINVAL

This sounds similar to https://github.com/stanislavlevin/pyproject_installer/issues/33 and https://github.com/Bachmann1234/diff_cover/issues/308.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the failing test at $(BUILD_DIR)/testing/_py/test_local.py:623 and the removal logic at /usr/lib/python3.9/vendor-packages/py/_path/local.py:218. Reproduce TestLocalPath.test_chdir_gone on OpenIndiana and compare the shutil.rmtree failure with the two referenced issues. Done means the test passes on OpenIndiana without regressing removal behavior elsewhere.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.