Skip to content

Commit 905b15e

Browse files
committed
Improve handling of file limit tests for JIT implementations
* Add checks for `IS_GRAALPY` and `IS_PYPY` to conditionally adjust file descriptor limits. * Refactor the test to use `pytest.raises` for more robust assertion of `OSError` during file descriptor exhaustion. * Ensure that the `EMFILE` error code and specific error message are checked for JIT environments. Signed-off-by: Emre Şafak <[email protected]>
1 parent e799e5b commit 905b15e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/unit/test_file_limit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import pytest
88

9+
from src.virtualenv.info import IS_GRAALPY, IS_PYPY
910
from virtualenv.info import IMPLEMENTATION
1011
from virtualenv.run import cli_run
1112

@@ -32,11 +33,10 @@ def test_too_many_open_files(tmp_path):
3233
fds = []
3334
try:
3435
# JIT implementations use more file descriptors up front so we can run out early
35-
try:
36-
fds.extend(os.open(os.devnull, os.O_RDONLY) for _ in range(20))
37-
except OSError as jit_exceptions: # pypy, graalpy
38-
assert jit_exceptions.errno == errno.EMFILE
39-
assert "Too many open files" in str(jit_exceptions)
36+
if IS_GRAALPY or IS_PYPY:
37+
with pytest.raises(OSError, match="Too many open files") as jit_exception:
38+
fds.extend(os.open(os.devnull, os.O_RDONLY) for _ in range(20))
39+
assert jit_exception.value.errno == errno.EMFILE
4040

4141
expected_exceptions = SystemExit, OSError, RuntimeError
4242
with pytest.raises(expected_exceptions) as too_many_open_files_exc:

0 commit comments

Comments
 (0)