Need to stop prometheus_client.http_server with Python code.
I have external Python application that is to be unit-tested. It has method that starts prometheus_client with start_http_server(port). I need to unit-test it with several tests (indeed I don't test prometheus but other functionalities but can't take prometheus out of the code). As I need several tests so I need to start-stop method several times, but it exits after first attempt as Prometheus client is holding port and can't start again on the same port (OSError: [Errno 48] Address already in use).
The question: is there any way to stop prometheus_client.http_server with Python? Didn't find anything in prometheus_client docs about shutting it down...
Well, it's not exact answer to my question but anyway: I decided to start_http_server = Mock(return_value=None) so that it's not starting in unit-tests.
Stop Prometheus client in python script