str0zzapreti / pytest-retry

A simple plugin for retrying flaky tests in CI environments
MIT License
27 stars 6 forks source link

1.6.0 `ReportServer` causes `OSError` #30

Closed andrewasheridan closed 6 months ago

andrewasheridan commented 6 months ago

Thank you for the very useful project.

Ran into this issue after bumping to 1.6.0:

The port binding fails if another test run is in progress:

https://github.com/str0zzapreti/pytest-retry/blob/c5d6207be7fa8a8fda452b909fd98a47fbcb6812/pytest_retry/server.py#L34

Traceback ```text 00:58:05 + /var/lib/jenkins/workspace/foo/venv/bin/pytest -vv --junitxml=/var/lib/jenkins/workspace/foo/pytest_results.xml --durations=10 --disable-socket --allow-hosts=127.0.0.1 --allow-unix-socket --retries=2 --retry-delay=3 --cov=food --cov-report=xml:coverage.xml --cov-fail-under=75 -n=auto /var/lib/jenkins/workspace/foo 00:58:06 INTERNALERROR> Traceback (most recent call last): 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/_pytest/main.py", line 267, in wrap_session 00:58:06 INTERNALERROR> config._do_configure() 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1053, in _do_configure 00:58:06 INTERNALERROR> self.hook.pytest_configure.call_historic(kwargs=dict(config=self)) 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/pluggy/_hooks.py", line 514, in call_historic 00:58:06 INTERNALERROR> res = self._hookexec(self.name, self._hookimpls, kwargs, False) 00:58:06 INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec 00:58:06 INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult) 00:58:06 INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/pluggy/_callers.py", line 113, in _multicall 00:58:06 INTERNALERROR> raise exception.with_traceback(exception.__traceback__) 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/pluggy/_callers.py", line 77, in _multicall 00:58:06 INTERNALERROR> res = hook_impl.function(*args) 00:58:06 INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^ 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/pytest_retry/retry_plugin.py", line 300, in pytest_configure 00:58:06 INTERNALERROR> retry_manager.reporter = ReportServer() 00:58:06 INTERNALERROR> ^^^^^^^^^^^^^^ 00:58:06 INTERNALERROR> File "/var/lib/jenkins/workspace/foo/venv/lib/python3.11/site-packages/pytest_retry/server.py", line 34, in __init__ 00:58:06 INTERNALERROR> self.sock.bind(("localhost", CONN_PORT)) 00:58:06 INTERNALERROR> OSError: [Errno 98] Address already in use ```

Perhaps bind to port 0?

Thank you again

str0zzapreti commented 6 months ago

Ah, you just helped me understand why I was getting an OSError when I initially tried port 0. Yeah, this shouldn't be too difficult, I'll have a hotfix out shortly. Sockets are neat.

str0zzapreti commented 6 months ago

Fixed in https://github.com/str0zzapreti/pytest-retry/pull/31, will be released in version 1.6.1