Skip to content
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

(Flaky) test failure: OSError via PosixPath.glob #6809

Open
blueyed opened this issue Feb 24, 2020 · 0 comments
Open

(Flaky) test failure: OSError via PosixPath.glob #6809

blueyed opened this issue Feb 24, 2020 · 0 comments
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed

Comments

@blueyed
Copy link
Contributor

blueyed commented Feb 24, 2020

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:

def test_try_makedirs(monkeypatch, tmp_path):
from _pytest.assertion.rewrite import try_makedirs
p = tmp_path / "foo"
# create
assert try_makedirs(str(p))
assert p.is_dir()
# already exist
assert try_makedirs(str(p))
# monkeypatch to simulate all error situations
def fake_mkdir(p, exist_ok=False, *, exc):
assert isinstance(p, str)
raise exc
monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=FileNotFoundError()))
assert not try_makedirs(str(p))
monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=NotADirectoryError()))
assert not try_makedirs(str(p))
monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=PermissionError()))
assert not try_makedirs(str(p))
err = OSError()
err.errno = errno.EROFS
monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=err))
assert not try_makedirs(str(p))
# unhandled OSError should raise
err = OSError()
err.errno = errno.ECHILD
monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=err))
with pytest.raises(OSError) as exc_info:
try_makedirs(str(p))
assert exc_info.value.errno == errno.ECHILD

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

@blueyed blueyed added the type: bug problem that needs to be addressed label Feb 24, 2020
@Zac-HD Zac-HD added the topic: rewrite related to the assertion rewrite mechanism label Feb 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: rewrite related to the assertion rewrite mechanism type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants