I have faced a very strange issue:
when I run our python test-cases with pytest, it starts to fails with the log below stating that too many files are open.
I have googled around, but haven’t found any solution and don’t have any glue what causes this behavioral
Can anybody help me (even if you need further information, please let me know).
<code>pytest -vvvv --setup-show tests
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.10, pytest-8.3.2, pluggy-1.5.0 -- <path>/.env/bin/python3
cachedir: .pytest_cache
rootdir: <path>
plugins: cov-5.0.0
collected 135 items / 3 errors
================================================================================================= ERRORS ==================================================================================================
________________________________________________________________________ ERROR collecting tests/functional/test_user_functional.py ________________________________________________________________________
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
???
<frozen importlib._bootstrap>:991: in _find_and_load
???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:671: in _load_unlocked
???
.env/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:165: in exec_module
source_stat, co = _rewrite_test(fn, self.config)
.env/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:343: in _rewrite_test
source = fn.read_bytes()
/usr/lib/python3.8/pathlib.py:1229: in read_bytes
???
/usr/lib/python3.8/pathlib.py:1222: in open
???
/usr/lib/python3.8/pathlib.py:1078: in _opener
???
E OSError: [Errno 24] Too many open files: '<path>/functional/test_user_functional.py'
____________________________________________________________________________________ ERROR collecting tests/test_data _____________________________________________________________________________________
.env/lib/python3.8/site-packages/_pytest/runner.py:341: in from_call
result: TResult | None = func()
.env/lib/python3.8/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
.env/lib/python3.8/site-packages/_pytest/main.py:523: in collect
for direntry in scandir(self.path):
.env/lib/python3.8/site-packages/_pytest/pathlib.py:885: in scandir
with os.scandir(path) as s:
E OSError: [Errno 24] Too many open files: '<path>/test_data'
_______________________________________________________________________________________ ERROR collecting tests/unit _______________________________________________________________________________________
.env/lib/python3.8/site-packages/_pytest/runner.py:341: in from_call
result: TResult | None = func()
.env/lib/python3.8/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
.env/lib/python3.8/site-packages/_pytest/main.py:523: in collect
for direntry in scandir(self.path):
.env/lib/python3.8/site-packages/_pytest/pathlib.py:885: in scandir
with os.scandir(path) as s:
E OSError: [Errno 24] Too many open files: '<path>/unit'
============================================================================================ warnings summary =============================================================================================
.env/lib/python3.8/site-packages/pydantic/_internal/_fields.py:201
<path>/.env/lib/python3.8/site-packages/pydantic/_internal/_fields.py:201: UserWarning: Field name "schema" in "SnowflakeConnectModel" shadows an attribute in parent "BaseModel"
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================================= short test summary info =========================================================================================
ERROR tests/functional/test_user_functional.py - OSError: [Errno 24] Too many open files: '<path>/functional/test_user_functional.py'
ERROR tests/test_data - OSError: [Errno 24] Too many open files: '<path>/test_data'
ERROR tests/unit - OSError: [Errno 24] Too many open files: '<path>/unit'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================================== 1 warning, 3 errors in 3.06s =======================================================================================
</code>
<code>pytest -vvvv --setup-show tests
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.10, pytest-8.3.2, pluggy-1.5.0 -- <path>/.env/bin/python3
cachedir: .pytest_cache
rootdir: <path>
plugins: cov-5.0.0
collected 135 items / 3 errors
================================================================================================= ERRORS ==================================================================================================
________________________________________________________________________ ERROR collecting tests/functional/test_user_functional.py ________________________________________________________________________
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
???
<frozen importlib._bootstrap>:991: in _find_and_load
???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:671: in _load_unlocked
???
.env/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:165: in exec_module
source_stat, co = _rewrite_test(fn, self.config)
.env/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:343: in _rewrite_test
source = fn.read_bytes()
/usr/lib/python3.8/pathlib.py:1229: in read_bytes
???
/usr/lib/python3.8/pathlib.py:1222: in open
???
/usr/lib/python3.8/pathlib.py:1078: in _opener
???
E OSError: [Errno 24] Too many open files: '<path>/functional/test_user_functional.py'
____________________________________________________________________________________ ERROR collecting tests/test_data _____________________________________________________________________________________
.env/lib/python3.8/site-packages/_pytest/runner.py:341: in from_call
result: TResult | None = func()
.env/lib/python3.8/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
.env/lib/python3.8/site-packages/_pytest/main.py:523: in collect
for direntry in scandir(self.path):
.env/lib/python3.8/site-packages/_pytest/pathlib.py:885: in scandir
with os.scandir(path) as s:
E OSError: [Errno 24] Too many open files: '<path>/test_data'
_______________________________________________________________________________________ ERROR collecting tests/unit _______________________________________________________________________________________
.env/lib/python3.8/site-packages/_pytest/runner.py:341: in from_call
result: TResult | None = func()
.env/lib/python3.8/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
.env/lib/python3.8/site-packages/_pytest/main.py:523: in collect
for direntry in scandir(self.path):
.env/lib/python3.8/site-packages/_pytest/pathlib.py:885: in scandir
with os.scandir(path) as s:
E OSError: [Errno 24] Too many open files: '<path>/unit'
============================================================================================ warnings summary =============================================================================================
.env/lib/python3.8/site-packages/pydantic/_internal/_fields.py:201
<path>/.env/lib/python3.8/site-packages/pydantic/_internal/_fields.py:201: UserWarning: Field name "schema" in "SnowflakeConnectModel" shadows an attribute in parent "BaseModel"
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================================= short test summary info =========================================================================================
ERROR tests/functional/test_user_functional.py - OSError: [Errno 24] Too many open files: '<path>/functional/test_user_functional.py'
ERROR tests/test_data - OSError: [Errno 24] Too many open files: '<path>/test_data'
ERROR tests/unit - OSError: [Errno 24] Too many open files: '<path>/unit'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================================== 1 warning, 3 errors in 3.06s =======================================================================================
</code>
pytest -vvvv --setup-show tests
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.10, pytest-8.3.2, pluggy-1.5.0 -- <path>/.env/bin/python3
cachedir: .pytest_cache
rootdir: <path>
plugins: cov-5.0.0
collected 135 items / 3 errors
================================================================================================= ERRORS ==================================================================================================
________________________________________________________________________ ERROR collecting tests/functional/test_user_functional.py ________________________________________________________________________
/usr/lib/python3.8/importlib/__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1014: in _gcd_import
???
<frozen importlib._bootstrap>:991: in _find_and_load
???
<frozen importlib._bootstrap>:975: in _find_and_load_unlocked
???
<frozen importlib._bootstrap>:671: in _load_unlocked
???
.env/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:165: in exec_module
source_stat, co = _rewrite_test(fn, self.config)
.env/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:343: in _rewrite_test
source = fn.read_bytes()
/usr/lib/python3.8/pathlib.py:1229: in read_bytes
???
/usr/lib/python3.8/pathlib.py:1222: in open
???
/usr/lib/python3.8/pathlib.py:1078: in _opener
???
E OSError: [Errno 24] Too many open files: '<path>/functional/test_user_functional.py'
____________________________________________________________________________________ ERROR collecting tests/test_data _____________________________________________________________________________________
.env/lib/python3.8/site-packages/_pytest/runner.py:341: in from_call
result: TResult | None = func()
.env/lib/python3.8/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
.env/lib/python3.8/site-packages/_pytest/main.py:523: in collect
for direntry in scandir(self.path):
.env/lib/python3.8/site-packages/_pytest/pathlib.py:885: in scandir
with os.scandir(path) as s:
E OSError: [Errno 24] Too many open files: '<path>/test_data'
_______________________________________________________________________________________ ERROR collecting tests/unit _______________________________________________________________________________________
.env/lib/python3.8/site-packages/_pytest/runner.py:341: in from_call
result: TResult | None = func()
.env/lib/python3.8/site-packages/_pytest/runner.py:389: in collect
return list(collector.collect())
.env/lib/python3.8/site-packages/_pytest/main.py:523: in collect
for direntry in scandir(self.path):
.env/lib/python3.8/site-packages/_pytest/pathlib.py:885: in scandir
with os.scandir(path) as s:
E OSError: [Errno 24] Too many open files: '<path>/unit'
============================================================================================ warnings summary =============================================================================================
.env/lib/python3.8/site-packages/pydantic/_internal/_fields.py:201
<path>/.env/lib/python3.8/site-packages/pydantic/_internal/_fields.py:201: UserWarning: Field name "schema" in "SnowflakeConnectModel" shadows an attribute in parent "BaseModel"
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================================= short test summary info =========================================================================================
ERROR tests/functional/test_user_functional.py - OSError: [Errno 24] Too many open files: '<path>/functional/test_user_functional.py'
ERROR tests/test_data - OSError: [Errno 24] Too many open files: '<path>/test_data'
ERROR tests/unit - OSError: [Errno 24] Too many open files: '<path>/unit'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================================== 1 warning, 3 errors in 3.06s =======================================================================================
ulimit output:
<code>ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 29053
max locked memory (kbytes, -l) 65536
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 29053
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
</code>
<code>ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 29053
max locked memory (kbytes, -l) 65536
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 29053
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
</code>
ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 29053
max locked memory (kbytes, -l) 65536
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 29053
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited