import ssl import socket def test_ssl_certificate(): hostname = "127.0.0.1" port = 443 context = ssl.create_default_context() with socket.create_connection((hostname, port)) as sock: with context.wrap_socket(sock, server_hostname=hostname) as ssock: cert = ssock.getpeercert() assert cert is not None, "No SSL certificate found!"