Plugin test suite: Improve output from 'Cannot connect to HERD' errors
Fixes #42 (closed)
With this change, in case of a typo in the hostname/port, or the HERD app having crashed, the output from the test suite is:
run-plugin-test-suite: error: argument --board: Could not connect to HERD application at wrong-hostname:3000
For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning
config = pluginmanager.hook.pytest_cmdline_parse(
ERROR: usage: run-plugin-test-suite [options] [file_or_dir] [file_or_dir] [...]
run-plugin-test-suite: error: argument --board: Could not connect to HERD application at wrong-hostname:3000
... whereas previously the output in the same scenario was:
Test session starts (platform: linux, Python 3.11.7, pytest 7.0.1, pytest-sugar 0.9.7)
cachedir: .pytest_cache
rootdir: /workspaces/pyswatch
plugins: repeat-0.9.3, sugar-0.9.7, check-1.0.10, anyio-4.4.0
/workspaces/pyswatch/src/swatch/board.py:599: RuntimeError: Could not connect to http://wrong-hostname:3000 (endpoint: /devices)
/workspaces/pyswatch/src/swatch/board.py:599: RuntimeError: Could not connect to http://wrong-hostname:3000 (endpoint: /devices)
collected 0 items / 2 errors
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_exceptions.py", line 10, in map_exceptions
INTERNALERROR> yield
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 100, in connect_tcp
INTERNALERROR> sock = socket.create_connection(
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/lib64/python3.11/socket.py", line 827, in create_connection
INTERNALERROR> for res in getaddrinfo(host, port, 0, SOCK_STREAM):
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/lib64/python3.11/socket.py", line 962, in getaddrinfo
INTERNALERROR> for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> socket.gaierror: [Errno -2] Name or service not known
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 60, in map_httpcore_exceptions
INTERNALERROR> yield
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 218, in handle_request
INTERNALERROR> resp = self._pool.handle_request(req)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 262, in handle_request
INTERNALERROR> raise exc
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection_pool.py", line 245, in handle_request
INTERNALERROR> response = connection.handle_request(request)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 92, in handle_request
INTERNALERROR> raise exc
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 69, in handle_request
INTERNALERROR> stream = self._connect(request)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_sync/connection.py", line 117, in _connect
INTERNALERROR> stream = self._network_backend.connect_tcp(**kwargs)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_backends/sync.py", line 99, in connect_tcp
INTERNALERROR> with map_exceptions(exc_map):
INTERNALERROR> File "/usr/lib64/python3.11/contextlib.py", line 158, in __exit__
INTERNALERROR> self.gen.throw(typ, value, traceback)
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
INTERNALERROR> raise to_exc(exc) from exc
INTERNALERROR> httpcore.ConnectError: [Errno -2] Name or service not known
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/workspaces/pyswatch/src/swatch/board.py", line 597, in __init__
INTERNALERROR> r = self._sync_client.get('/devices')
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1041, in get
INTERNALERROR> return self.request(
INTERNALERROR> ^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 814, in request
INTERNALERROR> return self.send(request, auth=auth, follow_redirects=follow_redirects)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 901, in send
INTERNALERROR> response = self._send_handling_auth(
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 929, in _send_handling_auth
INTERNALERROR> response = self._send_handling_redirects(
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 966, in _send_handling_redirects
INTERNALERROR> response = self._send_single_request(request)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1002, in _send_single_request
INTERNALERROR> response = transport.handle_request(request)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 217, in handle_request
INTERNALERROR> with map_httpcore_exceptions():
INTERNALERROR> File "/usr/lib64/python3.11/contextlib.py", line 158, in __exit__
INTERNALERROR> self.gen.throw(typ, value, traceback)
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/httpx/_transports/default.py", line 77, in map_httpcore_exceptions
INTERNALERROR> raise mapped_exc(message) from exc
INTERNALERROR> httpx.ConnectError: [Errno -2] Name or service not known
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/_pytest/main.py", line 268, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/_pytest/main.py", line 321, in _main
INTERNALERROR> config.hook.pytest_collection(session=session)
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_callers.py", line 182, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_result.py", line 100, in get_result
INTERNALERROR> raise exc.with_traceback(exc.__traceback__)
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/_pytest/main.py", line 332, in pytest_collection
INTERNALERROR> session.perform_collect()
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/_pytest/main.py", line 660, in perform_collect
INTERNALERROR> hook.pytest_collection_modifyitems(
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_callers.py", line 182, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_result.py", line 100, in get_result
INTERNALERROR> raise exc.with_traceback(exc.__traceback__)
INTERNALERROR> File "/usr/local/lib/python3.11/site-packages/pluggy/_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/workspaces/pyswatch/src/swatch/test_plugin/conftest.py", line 117, in pytest_collection_modifyitems
INTERNALERROR> board = Board(BoardStub('board', hostname=hostname, port=port))
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/workspaces/pyswatch/src/swatch/utilities/tracing.py", line 101, in wrapper
INTERNALERROR> return func(*args, **kwargs)
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "/workspaces/pyswatch/src/swatch/board.py", line 599, in __init__
INTERNALERROR> raise RuntimeError(f'Could not connect to {self._baseURL} (endpoint: /devices)')
INTERNALERROR> RuntimeError: Could not connect to http://wrong-hostname:3000 (endpoint: /devices)