How to use the respx.add function in respx

To help you get started, we’ve selected a few respx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lundberg / respx / tests / test_mock.py View on Github external
async def test_start_stop(client):
    url = "https://foo.bar/"
    request = respx.add("GET", url, status_code=202)
    assert respx.stats.call_count == 0

    try:
        respx.start()
        response = await client.get(url)
        assert request.called is True
        assert response.status_code == 202
        assert response.text == ""
        assert respx.stats.call_count == 1

        respx.stop(clear=False, reset=False)
        assert len(respx.mock.patterns) == 1
        assert respx.stats.call_count == 1
        assert request.called is True

        respx.reset()