    def test_reports_metrics(self):
        """
        ``MetricsResource`` serves the metrics from the provided registry.
        """
        c = Counter('cc', 'A counter', registry=self.registry)
        c.inc()

        root = Resource()
        root.putChild(b'metrics', MetricsResource(registry=self.registry))
        server = reactor.listenTCP(0, Site(root))
        self.addCleanup(server.stopListening)

        agent = Agent(reactor)
        port = server.getHost().port
        url = f"http://localhost:{port}/metrics"
        d = agent.request(b"GET", url.encode("ascii"))

        # Ignore expected DeprecationWarning.
        filterwarnings("ignore", category=DeprecationWarning, message="Using readBody "
                       "with a transport that does not have an abortConnection method")

        d.addCallback(readBody)
        d.addCallback(self.assertEqual, generate_latest(self.registry))

        return d
``MetricsResource`` serves the metrics from the provided registry.
tests/test_twisted.py