Skip to content

test_too_many_open_files only works on GNU-libc systems #3000

@pltrz

Description

@pltrz

In an attempt to update the package on Alpine Linux from 20.32.0 to 20.35.4, I went about the standard process by updating the package recipe and testing. 1 test failed (test_too_many_open_files).

So, just to be sure errors aren't introduced by the distro's packaging/build system, I went ahead to clone and setup direct from the source, but experienced the same failure on test_too_many_open_files.

Any ideas?

$ git clone https://github.com/pypa/virtualenv/

$ cd ./virtualenv/

$ tox -e py

ROOT: will run in automatically provisioned tox, host /usr/bin/python3 is missing [requires (has)]: tox>=4.28 (4.27.0)
ROOT: install_deps> python -I -m pip install tox 'tox>=4.28'
ROOT: provision> .tox/.tox/bin/python -m tox -e py
.pkg: install_requires> python -I -m pip install 'hatch-vcs>=0.3' 'hatchling>=1.17.1'
.pkg: _optional_hooks> python /home/pltrz/src/virtualenv/.tox/.tox/lib/python3.12/site-packages/pyproject_api/_backend.py True hatchling.build
.pkg: get_requires_for_build_wheel> python /home/pltrz/src/virtualenv/.tox/.tox/lib/python3.12/site-packages/pyproject_api/_backend.py True hatchling.build
.pkg: get_requires_for_build_editable> python /home/pltrz/src/virtualenv/.tox/.tox/lib/python3.12/site-packages/pyproject_api/_backend.py True hatchling.build
.pkg: install_requires_for_build_editable> python -I -m pip install 'editables~=0.3'
.pkg: build_wheel> python /home/pltrz/src/virtualenv/.tox/.tox/lib/python3.12/site-packages/pyproject_api/_backend.py True hatchling.build
py: install_package_deps> python -I -m pip install 'covdefaults>=2.3' 'coverage-enable-subprocess>=1' 'coverage>=7.2.7' 'distlib<1,>=0.3.7' 'filelock<4,>=3.12.2' 'flaky>=3.7' 'importlib-metadata>=6.6; python_version < "3.8"' 'packaging>=23.1' 'platformdirs<5,>=3.9.1' 'pytest-env>=0.8.2' 'pytest-freezer>=0.4.8; platform_python_implementation == "PyPy" or platform_python_implementation == "GraalVM" or (platform_python_implementation == "CPython" and sys_platform == "win32" and python_version >= "3.13")' 'pytest-mock>=3.11.1' 'pytest-randomly>=3.12' 'pytest-timeout>=2.1' 'pytest>=7.4' 'setuptools>=68' 'time-machine>=2.10; platform_python_implementation == "CPython"' 'typing-extensions>=4.13.2; python_version < "3.11"'
py: install_package> python -I -m pip install --force-reinstall --no-deps /home/pltrz/src/virtualenv/.tox/.tmp/package/1/virtualenv-20.35.4.dev18+g5d09a90f8-py3-none-any.whl
py: commands[0]> coverage erase
py: commands[1]> coverage run -m pytest --junitxml /home/pltrz/src/virtualenv/.tox/junit.py.xml tests --int
======================================= test session starts ========================================
platform linux -- Python 3.12.12, pytest-9.0.2, pluggy-1.6.0
cachedir: .tox/py/.pytest_cache
Using --randomly-seed=468341791
rootdir: /home/pltrz/src/virtualenv
configfile: pyproject.toml
plugins: time-machine-3.1.0, flaky-3.8.1, timeout-2.4.0, randomly-4.0.1, mock-3.15.1, env-1.2.0
timeout: 600.0s
timeout method: signal
timeout func_only: False
collected 398 items

tests/unit/test_util.py ..                                                                   [  0%]
tests/unit/activation/test_activator.py .                                                    [  0%]
tests/unit/seed/embed/test_base_embed.py ........s....ss..s                                  [  5%]
tests/unit/create/test_interpreters.py .                                                     [  5%]
tests/unit/test_file_limit.py F                                                              [  5%]
tests/unit/create/via_global_ref/builtin/pypy/test_pypy3.py ...                              [  6%]
tests/unit/activation/test_csh.py ..s                                                        [  7%]
tests/unit/activation/test_bash.py ..                                                        [  7%]
tests/unit/activation/test_python_activator.py .                                             [  8%]
tests/unit/activation/test_fish.py s                                                         [  8%]
tests/unit/activation/test_batch.py ss                                                       [  8%]
tests/unit/activation/test_nushell.py s                                                      [  9%]
tests/unit/activation/test_csh.py s                                                          [  9%]
tests/unit/activation/test_bash.py ..                                                        [  9%]
tests/unit/activation/test_python_activator.py .                                             [ 10%]
tests/unit/activation/test_fish.py s                                                         [ 10%]
tests/unit/activation/test_batch.py ss                                                       [ 10%]
tests/unit/activation/test_nushell.py s                                                      [ 11%]
tests/unit/create/via_global_ref/builtin/cpython/test_cpython3_win.py ........               [ 13%]
tests/unit/seed/wheels/test_wheels_util.py .....                                             [ 14%]
tests/unit/config/cli/test_parser.py ...                                                     [ 15%]
tests/unit/discovery/py_info/test_py_info.py .....................s......s.................. [ 26%]
.....                                                                                        [ 28%]
tests/unit/discovery/test_discovery.py ........................                              [ 34%]
tests/unit/create/via_global_ref/test_api.py .                                               [ 34%]
tests/unit/activation/test_bash.py ..                                                        [ 34%]
tests/unit/discovery/test_py_spec.py .....................................................   [ 48%]
tests/unit/config/test_env_var.py ........                                                   [ 50%]
tests/unit/seed/wheels/test_acquire_find_wheel.py ....                                       [ 51%]
tests/unit/seed/wheels/test_periodic_update.py ...........................                   [ 58%]
tests/unit/discovery/windows/test_windows.py ssssssssssss                                    [ 61%]
tests/unit/activation/test_activation_support.py ............                                [ 64%]
tests/unit/test_run.py ....                                                                  [ 65%]
tests/unit/seed/wheels/test_acquire.py .........                                             [ 67%]
tests/unit/config/test_ini.py .                                                              [ 67%]
tests/unit/discovery/py_info/test_py_info_exe_based_of.py .........................          [ 73%]
tests/unit/create/test_creator.py ...........................JK.s..........ss............      [ 87%]
tests/unit/seed/wheels/test_bundle.py .....                                                  [ 88%]
tests/unit/discovery/windows/test_windows_pep514.py ss                                       [ 88%]
tests/unit/activation/test_powershell.py ..                                                  [ 89%]
tests/unit/activation/test_fish.py ..                                                        [ 89%]
tests/unit/activation/test_batch.py ..                                                       [ 90%]
tests/unit/seed/embed/test_bootstrap_link_via_app_data.py ..                                 [ 90%]
tests/unit/activation/test_nushell.py .                                                      [ 91%]
tests/unit/create/via_global_ref/test_race_condition.py ..                                   [ 91%]
tests/unit/config/test___main__.py .......                                                   [ 93%]
tests/unit/create/via_global_ref/test_build_c_ext.py ..                                      [ 93%]
tests/unit/create/test_interpreters.py .                                                     [ 94%]
tests/unit/activation/test_powershell.py ss                                                  [ 94%]
tests/unit/create/test_creator.py ..                                                         [ 95%]
tests/unit/seed/embed/test_pip_invoke.py ....                                                [ 96%]
tests/unit/seed/embed/test_bootstrap_link_via_app_data.py ..s.....                           [ 98%]
tests/integration/test_cachedir_tag.py .                                                     [ 98%]
tests/integration/test_race_condition_simulation.py .                                        [ 98%]
tests/integration/test_run_int.py .                                                          [ 98%]
tests/integration/test_zipapp.py ....                                                        [100%]

============================================= FAILURES =============================================
_____________________________________ test_too_many_open_files _____________________________________

tmp_path = PosixPath('/tmp/pytest-of-pltrz/pytest-7/test_too_many_open_files0')

    @pytest.mark.skipif(sys.platform == "win32", reason="resource module not available on Windows")
    def test_too_many_open_files(tmp_path):
        """
        Test that we get a specific error message when we have too many open files.
        """
        import resource  # noqa: PLC0415

        soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)

        # Lower the soft limit to a small number to trigger the error
        try:
            resource.setrlimit(resource.RLIMIT_NOFILE, (32, hard_limit))
        except ValueError:
            pytest.skip("could not lower the soft limit for open files")
        except AttributeError as exc:  # pypy, graalpy
            if "module 'resource' has no attribute 'setrlimit'" in str(exc):
                pytest.skip(f"{IMPLEMENTATION} does not support resource.setrlimit")

        # Keep some file descriptors open to make it easier to trigger the error
        fds = []
        try:
            # JIT implementations use more file descriptors up front so we can run out early
            try:
                fds.extend(os.open(os.devnull, os.O_RDONLY) for _ in range(20))
            except OSError as jit_exceptions:  # pypy, graalpy
                assert jit_exceptions.errno == errno.EMFILE  # noqa: PT017
                assert "Too many open files" in str(jit_exceptions)  # noqa: PT017

            expected_exceptions = SystemExit, OSError, RuntimeError
            with pytest.raises(expected_exceptions) as too_many_open_files_exc:
                cli_run([str(tmp_path / "venv")])

            if isinstance(too_many_open_files_exc, SystemExit):
                assert too_many_open_files_exc.code != 0
            else:
>               assert "Too many open files" in str(too_many_open_files_exc.value)
E               assert 'Too many open files' in "failed to query /home/pltrz/src/virtualenv/.tox/py/bin/python with code 24 err: 'No file descriptors available'"
E                +  where "failed to query /home/pltrz/src/virtualenv/.tox/py/bin/python with code 24 err: 'No file descriptors available'" = str(RuntimeError("failed to query /home/pltrz/src/virtualenv/.tox/py/bin/python with code 24 err: 'No file descriptors available'"))
E                +    where RuntimeError("failed to query /home/pltrz/src/virtualenv/.tox/py/bin/python with code 24 err: 'No file descriptors available'") = <ExceptionInfo RuntimeError("failed to query /home/pltrz/src/virtualenv/.tox/py/bin/python with code 24 err: 'No file descriptors available'") tblen=11>.value

expected_exceptions = (<class 'SystemExit'>, <class 'OSError'>, <class 'RuntimeError'>)
fd         = 30
fds        = [11, 12, 13, 14, 15, 16, ...]
hard_limit = 4096
resource   = <module 'resource' from '/usr/lib/python3.12/lib-dynload/resource.cpython-312-x86_64-linux-musl.so'>
soft_limit = 1024
tmp_path   = PosixPath('/tmp/pytest-of-pltrz/pytest-7/test_too_many_open_files0')
too_many_open_files_exc = <ExceptionInfo RuntimeError("failed to query /home/pltrz/src/virtualenv/.tox/py/bin/python with code 24 err: 'No file descriptors available'") tblen=11>

tests/unit/test_file_limit.py:48: AssertionError
-------------------------------------- Captured log teardown ---------------------------------------
DEBUG    filelock:_api.py:331 Attempting to acquire lock 140419667361232 on /tmp/pytest-of-pltrz/pytest-7/session-app-data0/py_info/2/.lock
DEBUG    filelock:_api.py:334 Lock 140419667361232 acquired on /tmp/pytest-of-pltrz/pytest-7/session-app-data0/py_info/2/.lock
DEBUG    filelock:_api.py:364 Attempting to release lock 140419667361232 on /tmp/pytest-of-pltrz/pytest-7/session-app-data0/py_info/2/.lock
DEBUG    filelock:_api.py:367 Lock 140419667361232 released on /tmp/pytest-of-pltrz/pytest-7/session-app-data0/py_info/2/.lock
----------------- generated xml file: /home/pltrz/src/virtualenv/.tox/junit.py.xml -----------------
===================================== short test summary info ======================================
FAILED tests/unit/test_file_limit.py::test_too_many_open_files - assert 'Too many open files' in "failed to query /home/pltrz/src/virtualenv/.tox/py/bin/python ...
====================== 1 failed, 361 passed, 36 skipped in 177.77s (0:02:57) =======================
/home/pltrz/src/virtualenv/.tox/py/lib/python3.12/site-packages/_pytest/pathlib.py:96: PytestWarning: (rm_rf) error removing /tmp/pytest-of-pltrz/garbage-4aef53bd-a547-4faf-bff7-567e67b11be6/popen-gw10/test_discovery_via_path_in_non0
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-pltrz/garbage-4aef53bd-a547-4faf-bff7-567e67b11be6/popen-gw10/test_discovery_via_path_in_non0'
  warnings.warn(
/home/pltrz/src/virtualenv/.tox/py/lib/python3.12/site-packages/_pytest/pathlib.py:96: PytestWarning: (rm_rf) error removing /tmp/pytest-of-pltrz/garbage-4aef53bd-a547-4faf-bff7-567e67b11be6/popen-gw10
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-pltrz/garbage-4aef53bd-a547-4faf-bff7-567e67b11be6/popen-gw10'
  warnings.warn(
/home/pltrz/src/virtualenv/.tox/py/lib/python3.12/site-packages/_pytest/pathlib.py:96: PytestWarning: (rm_rf) error removing /tmp/pytest-of-pltrz/garbage-4aef53bd-a547-4faf-bff7-567e67b11be6
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-pltrz/garbage-4aef53bd-a547-4faf-bff7-567e67b11be6'
  warnings.warn(
/home/pltrz/src/virtualenv/.tox/py/lib/python3.12/site-packages/_pytest/pathlib.py:96: PytestWarning: (rm_rf) error removing /tmp/pytest-of-pltrz/garbage-0ca535e3-52b0-477a-aebe-1623828bf514/popen-gw10/test_discovery_via_path_in_non0
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-pltrz/garbage-0ca535e3-52b0-477a-aebe-1623828bf514/popen-gw10/test_discovery_via_path_in_non0'
  warnings.warn(
/home/pltrz/src/virtualenv/.tox/py/lib/python3.12/site-packages/_pytest/pathlib.py:96: PytestWarning: (rm_rf) error removing /tmp/pytest-of-pltrz/garbage-0ca535e3-52b0-477a-aebe-1623828bf514/popen-gw10
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-pltrz/garbage-0ca535e3-52b0-477a-aebe-1623828bf514/popen-gw10'
  warnings.warn(
/home/pltrz/src/virtualenv/.tox/py/lib/python3.12/site-packages/_pytest/pathlib.py:96: PytestWarning: (rm_rf) error removing /tmp/pytest-of-pltrz/garbage-0ca535e3-52b0-477a-aebe-1623828bf514
<class 'OSError'>: [Errno 39] Directory not empty: '/tmp/pytest-of-pltrz/garbage-0ca535e3-52b0-477a-aebe-1623828bf514'
  warnings.warn(
py: exit 1 (179.23 seconds) /home/pltrz/src/virtualenv> coverage run -m pytest --junitxml /home/pltrz/src/virtualenv/.tox/junit.py.xml tests --int pid=28099
.pkg: _exit> python /home/pltrz/src/virtualenv/.tox/.tox/lib/python3.12/site-packages/pyproject_api/_backend.py True hatchling.build
  py: FAIL code 1 (198.92=setup[19.45]+cmd[0.24,179.23] seconds)
  evaluation failed :( (198.97 seconds)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions