-
Notifications
You must be signed in to change notification settings - Fork 9
Description
What happened?
We started treating warnings as errors when running tests, and when using the minimal dependencies, we have a test that sometimes triggers a warning about an unclosed socket in hypothesis.
What did you expect instead?
Tests to run without warnings.
Affected version(s)
No response
Affected part(s)
Unit, integration and performance tests (part:tests)
Extra information
As a workaround, we can use @pytest.mark.filterwarnings on the failing test. In the future we probably need to upgrade the minimum dependencies.
Even when the failure seems to be present in hypothesis, its version is the same in pytest_min and pytest_max, so either the flakyness also happens with pytest_max too but it is much less likely and we haven't observed it, or it is another dependency that's causing the issue. We have a very old version of watchfiles as minimum dependency, my bet is on that one for now...
Here is the warning (in this CI run):
=================================== FAILURES ===================================
________________________ test_policy_trigger_all_missed ________________________
cls = <class '_pytest.runner.CallInfo'>
func = <function call_and_report.<locals>.<lambda> at 0x7f0ab0fc4ea0>
when = 'call'
reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)
@classmethod
def from_call(
cls,
func: Callable[[], TResult],
when: Literal["collect", "setup", "call", "teardown"],
reraise: type[BaseException] | tuple[type[BaseException], ...] | None = None,
) -> CallInfo[TResult]:
"""Call func, wrapping the result in a CallInfo.
:param func:
The function to call. Called without arguments.
:type func: Callable[[], _pytest.runner.TResult]
:param when:
The phase in which the function is called.
:param reraise:
Exception or exceptions that shall propagate if raised by the
function, instead of being wrapped in the CallInfo.
"""
excinfo = None
start = timing.time()
precise_start = timing.perf_counter()
try:
> result: TResult | None = func()
.nox/pytest_min/lib/python3.11/site-packages/_pytest/runner.py:341:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.nox/pytest_min/lib/python3.11/site-packages/_pytest/runner.py:242: in <lambda>
lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
.nox/pytest_min/lib/python3.11/site-packages/pluggy/_hooks.py:513: in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
.nox/pytest_min/lib/python3.11/site-packages/pluggy/_manager.py:120: in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
.nox/pytest_min/lib/python3.11/site-packages/_pytest/threadexception.py:92: in pytest_runtest_call
yield from thread_exception_runtest_hook()
.nox/pytest_min/lib/python3.11/site-packages/_pytest/threadexception.py:68: in thread_exception_runtest_hook
yield
.nox/pytest_min/lib/python3.11/site-packages/_pytest/unraisableexception.py:95: in pytest_runtest_call
yield from unraisable_exception_runtest_hook()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def unraisable_exception_runtest_hook() -> Generator[None]:
with catch_unraisable_exception() as cm:
try:
yield
finally:
if cm.unraisable:
if cm.unraisable.err_msg is not None:
err_msg = cm.unraisable.err_msg
else:
err_msg = "Exception ignored in"
msg = f"{err_msg}: {cm.unraisable.object!r}\n\n"
msg += "".join(
traceback.format_exception(
cm.unraisable.exc_type,
cm.unraisable.exc_value,
cm.unraisable.exc_traceback,
)
)
> warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
E pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=-1, family=1, type=1, proto=0>
E
E Traceback (most recent call last):
E File "/home/runner/work/frequenz-channels-python/frequenz-channels-python/.nox/pytest_min/lib/python3.11/site-packages/hypothesis/core.py", line 1237, in run_engine
E database_key = self.wrapped_test._hypothesis_internal_database_key
E ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E AttributeError: 'function' object has no attribute '_hypothesis_internal_database_key'
E
E During handling of the above exception, another exception occurred:
E
E Traceback (most recent call last):
E File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/ast.py", line 50, in parse
E return compile(source, filename, mode, flags,
E ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E ResourceWarning: unclosed <socket.socket fd=16, family=1, type=1, proto=0>
.nox/pytest_min/lib/python3.11/site-packages/_pytest/unraisableexception.py:85: PytestUnraisableExceptionWarning
=========================== short test summary info ============================
FAILED tests/test_timer.py::test_policy_trigger_all_missed - pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=-1, family=1, type=1, proto=0>
Traceback (most recent call last):
File "/home/runner/work/frequenz-channels-python/frequenz-channels-python/.nox/pytest_min/lib/python3.11/site-packages/hypothesis/core.py", line 1237, in run_engine
database_key = self.wrapped_test._hypothesis_internal_database_key
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'function' object has no attribute '_hypothesis_internal_database_key'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/hostedtoolcache/Python/3.11.11/x64/lib/python3.11/ast.py", line 50, in parse
return compile(source, filename, mode, flags,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ResourceWarning: unclosed <socket.socket fd=16, family=1, type=1, proto=0>
======================== 1 failed, 99 passed in 42.06s =========================