Ver Fonte

tests: fixture type hints and style standardization

Nicolas Duchon há 5 meses atrás
pai
commit
ae0c9a8e96

+ 9 - 9
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
     """

+ 2 - 2
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.

+ 1 - 1
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.