From ae0c9a8e96b123c8bf78cd01a8196338c433ccf2 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Fri, 27 Dec 2024 21:36:07 +0100 Subject: [PATCH] tests: fixture type hints and style standardization --- test/conftest.py | 18 +++++++++--------- test/test_events/test_events.py | 4 ++-- test/test_virtual-path/test_virtual-paths.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index d8961d3..7925ad3 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -6,7 +6,7 @@ import shlex import socket import subprocess import time -from typing import List, Optional +from typing import Iterator, List, Optional import backoff import docker.errors @@ -330,7 +330,7 @@ def wait_for_nginxproxy_to_be_ready(): @pytest.fixture -def docker_compose_file(request: FixtureRequest) -> Optional[str]: +def docker_compose_file(request: FixtureRequest) -> Iterator[Optional[str]]: """Fixture naming the docker compose file to consider. If a YAML file exists with the same name as the test module (with the `.py` extension replaced @@ -462,13 +462,13 @@ class DockerComposer(contextlib.AbstractContextManager): @pytest.fixture(scope="module") -def docker_composer() -> DockerComposer: +def docker_composer() -> Iterator[DockerComposer]: with DockerComposer() as d: yield d @pytest.fixture -def ca_root_certificate() -> str: +def ca_root_certificate() -> Iterator[str]: yield CA_ROOT_CERTIFICATE @@ -480,7 +480,7 @@ def monkey_patched_dns(): @pytest.fixture -def docker_compose(monkey_patched_dns, docker_composer, docker_compose_file) -> DockerClient: +def docker_compose(monkey_patched_dns, docker_composer, docker_compose_file) -> Iterator[DockerClient]: """Ensures containers described in a docker compose file are started. A custom docker compose file name can be specified by overriding the `docker_compose_file` @@ -493,8 +493,8 @@ def docker_compose(monkey_patched_dns, docker_composer, docker_compose_file) -> yield docker_client -@pytest.fixture() -def nginxproxy() -> RequestsForDocker: +@pytest.fixture +def nginxproxy() -> Iterator[RequestsForDocker]: """ Provides the `nginxproxy` object that can be used in the same way the requests module is: @@ -510,8 +510,8 @@ def nginxproxy() -> RequestsForDocker: yield RequestsForDocker() -@pytest.fixture() -def acme_challenge_path() -> str: +@pytest.fixture +def acme_challenge_path() -> Iterator[str]: """ Provides fake Let's Encrypt ACME challenge path used in certain tests """ diff --git a/test/test_events/test_events.py b/test/test_events/test_events.py index 72821d8..e137c87 100644 --- a/test/test_events/test_events.py +++ b/test/test_events/test_events.py @@ -7,7 +7,7 @@ import pytest from docker.errors import NotFound -@pytest.fixture() +@pytest.fixture def web1(docker_compose): """ pytest fixture creating a web container with `VIRTUAL_HOST=web1.nginx-proxy` listening on port 81. @@ -30,7 +30,7 @@ def web1(docker_compose): except NotFound: pass -@pytest.fixture() +@pytest.fixture def web2(docker_compose): """ pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy`, `VIRTUAL_PATH=/web2/` and `VIRTUAL_DEST=/` listening on port 82. diff --git a/test/test_virtual-path/test_virtual-paths.py b/test/test_virtual-path/test_virtual-paths.py index 4ba42aa..a8cd276 100644 --- a/test/test_virtual-path/test_virtual-paths.py +++ b/test/test_virtual-path/test_virtual-paths.py @@ -23,7 +23,7 @@ def test_invalid_path(docker_compose, nginxproxy, stub): r = nginxproxy.get(f"http://{stub}/port") assert r.status_code in [404, 503] -@pytest.fixture() +@pytest.fixture def web4(docker_compose): """ pytest fixture creating a web container with `VIRTUAL_HOST=nginx-proxy.test`, `VIRTUAL_PATH=/web4/` and `VIRTUAL_DEST=/` listening on port 84.