pytest-dev / pytest-dev/pytest

(Flaky) test failure: OSError via PosixPath.glob

Open
#6,809 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

testing/test_assertrewrite.py::test_try_makedirs failed with "OSError: [Errno
22]" via pathlib.Path.glob:

py38-xdist run-test: commands[0] | coverage run -m pytest -n auto
============================= test session starts ==============================
platform darwin -- Python 3.8.1, pytest-5.3.5.dev396+gc0826bc8d, py-1.8.1, pluggy-0.13.1
cachedir: .tox/py38-xdist/.pytest_cache
rootdir: /Users/runner/runners/2.165.2/work/pytest/pytest, inifile: tox.ini, testpaths: testing
plugins: hypothesis-5.5.4, xdist-1.31.0, forked-1.1.3
gw0 I / gw1 I / gw2 I / gw3 I
gw0 [2686] / gw1 [2686] / gw2 [2686] / gw3 [2686]

.....ss...............................s................................. [  2%]
..............E...............................................s.......... [  5%]
…
==================================== ERRORS ====================================
_____________________ ERROR at setup of test_try_makedirs ______________________
[gw3] darwin -- Python 3.8.1 /Users/runner/runners/2.165.2/work/pytest/pytest/.tox/py38-xdist/bin/python

self = PosixPath('/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pytest-of-runner')
pattern = 'garbage-*'

    def glob(self, pattern):
        """Iterate over this subtree and yield all existing files (of any
        kind, including directories) matching the given relative pattern.
        """
        if not pattern:
            raise ValueError("Unacceptable pattern: {!r}".format(pattern))
        drv, root, pattern_parts = self._flavour.parse_parts((pattern,))
        if drv or root:
            raise NotImplementedError("Non-relative patterns are unsupported")
        selector = _make_selector(tuple(pattern_parts), self._flavour)
>       for p in selector.select_from(self):

/Users/runner/hostedtoolcache/Python/3.8.1/x64/lib/python3.8/pathlib.py:1133: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pathlib._WildcardSelector object at 0x1125354f0>
parent_path = PosixPath('/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pytest-of-runner')
is_dir = <function Path.is_dir at 0x10f54f5e0>
exists = <function Path.exists at 0x10f54f550>
scandir = <built-in function scandir>

    def _select_from(self, parent_path, is_dir, exists, scandir):
        try:
            entries = list(scandir(parent_path))
            for entry in entries:
                entry_is_dir = False
                try:
>                   entry_is_dir = entry.is_dir()
E                   OSError: [Errno 22] Invalid argument: '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pytest-of-runner/pytest-current'

/Users/runner/hostedtoolcache/Python/3.8.1/x64/lib/python3.8/pathlib.py:536: OSError
=============================== warnings summary ===============================
testing/test_cacheprovider.py:40
  /Users/runner/runners/2.165.2/work/pytest/pytest/testing/test_cacheprovider.py:40: PytestCacheWarning: could not create cache path /private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/pytest-of-runner/pytest-1/test_cache_writefail_cachfile_silent0/.pytest_cache/v/test/broken
    cache.set("test/broken", [])

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=========================== short test summary info ============================
ERROR testing/test_assertrewrite.py::test_try_makedirs - OSError: [Errno 22] ...
= 2591 passed, 84 skipped, 10 xfailed, 1 warning, 1 error in 101.45s (0:01:41) =
ERROR: InvocationError for command /Users/runner/runners/2.165.2/work/pytest/pytest/.tox/py38-xdist/bin/coverage run -m pytest -n auto (exited with code 1)
___________________________________ summary ____________________________________
ERROR:   py38-xdist: commands failed

As mentioned earlier it is bad that the exception context is lost here.

Code ref: https://github.com/pytest-dev/pytest/blob/d98dca33b5770d68f8b43e30aea4351dd176fe71/testing/test_assertrewrite.py#L1567-L1604

Build: https://github.com/pytest-dev/pytest/pull/6808/checks?check_run_id=464820845

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 testing/test_assertrewrite.py around test_try_makedirs, then run that test on the affected macOS/Python 3.8 configuration. Investigate the pathlib.Path.glob OSError and the lost exception context described in the report; the work is done when the test no longer flakes and the relevant failure context is retained.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
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.