File: test_timeout.py

package info (click to toggle)
python-glances-api 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: python: 675; makefile: 8; sh: 5
file content (23 lines) | stat: -rw-r--r-- 681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Test the interaction with the currencylayer API."""
import httpx
import pytest
from pytest_httpx import HTTPXMock

from glances_api import Glances, exceptions


@pytest.mark.asyncio
async def test_timeout(httpx_mock: HTTPXMock) -> None:
    """Test if the connection is hitting the timeout."""

    def raise_timeout(request):
        """Set the timeout for the requests."""
        raise httpx.ReadTimeout(
            f"Unable to read within {request.extensions['timeout']}", request=request
        )

    httpx_mock.add_callback(raise_timeout)

    with pytest.raises(exceptions.GlancesApiConnectionError):
        client = Glances()
        await client.get_metrics("mem")