You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using api4jenkins with pytest, it may happen that the following exception occurs:
def unraisable_exception_runtest_hook() -> Generator[None, None, None]: with catch_unraisable_exception() as cm: yield 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=10, type=1, proto=6>E E Traceback (most recent call last):E File "/usr/lib64/python3.11/encodings/idna.py", line 155, in encodeE result = input.encode('ascii')E ^^^^^^^^^^^^^^^^^^^^^E ResourceWarning: unclosed <socket.socket fd=34, family=10, type=1, proto=6, laddr=('::1', 48440, 0, 0), raddr=('::1', 50001, 0, 0)>
This is because the http_client in the Jenkins class constructor (and probably the async version, too) isn't closed after being used. I think the garbage collector of python isn't working properly in this case because the jenkins object (instance) is being passed into all BaseItem items as reference.
As a workaround, the http client can be closed manually:
jenkins_client=Jenkins(...)
# Do something with the clientclient.get_job(...)
# Close the http clientjenkins_client.http_client.close()
but I'd suggest to wrap the http client in an (auto closing) context manager or something like that.
The text was updated successfully, but these errors were encountered:
@joelee2012 you're right, my tests are failing because I run them in warnings as errors mode.
This is indeed similar to the linked issue but I still think that wrapping the socket in a context manager here would be a good idea.
When using
api4jenkins
with pytest, it may happen that the following exception occurs:This is because the
http_client
in theJenkins
class constructor (and probably the async version, too) isn't closed after being used. I think the garbage collector of python isn't working properly in this case because the jenkins object (instance) is being passed into allBaseItem
items as reference.As a workaround, the http client can be closed manually:
but I'd suggest to wrap the http client in an (auto closing) context manager or something like that.
The text was updated successfully, but these errors were encountered: