How to test an infinitely iterative subprocess in python?

Viewed 28

I am trying to test a class that serves Prometheus metrics using aioprometheus. The solutions I've seen used are to set a side effect for a PropertyMock and that has not worked for me; the service continues to run forever

PropertyMock(side_effect=[True, False])

Property Mock Example

Any help is appreciated:

@pytest.mark.unit
@pytest.mark.asyncio
@mock.patch("aioprometheus.service.Service")
async def test_async_code(mock_server, disable_sockets):
    server = LatencyMetricsServer(metrics_server=mock_server)
    with mock.patch(
        "app.server.LatencyMetricsServer.is_running",
        new_callable=mock.PropertyMock(),
        side_effect=[True, False],
    ):
        server.is_running = mock.PropertyMock(side_effect=True)
        with mock.patch.object(
            ping, "return_ping_statistics", side_effect=NameLookupError("test")
        ):
            with pytest.raises(NameLookupError):
                await server.start()
0 Answers
Related