Explorar o código

tests: cleanup test code

- remove unused imports in test cases
- fix code smells and code style in conftest.py
Nicolas Duchon hai 5 meses
pai
achega
b5dea1cf50
Modificáronse 67 ficheiros con 83 adicións e 156 borrados
  1. 48 30
      test/conftest.py
  2. 1 0
      test/requirements/python-requirements.txt
  3. 0 2
      test/test_DOCKER_HOST_unix_socket.py
  4. 0 3
      test/test_acme_http_challenge_location/test_acme_challenge_location_disabled.py
  5. 0 3
      test/test_acme_http_challenge_location/test_acme_challenge_location_enabled_is_default.py
  6. 0 3
      test/test_acme_http_challenge_location/test_acme_challenge_location_legacy.py
  7. 4 2
      test/test_build.py
  8. 0 1
      test/test_custom-error-page/test_custom-error-page.py
  9. 0 2
      test/test_custom/test_defaults-location.py
  10. 0 2
      test/test_custom/test_defaults.py
  11. 0 2
      test/test_custom/test_location-per-vhost.py
  12. 0 2
      test/test_custom/test_per-vhost.py
  13. 0 2
      test/test_custom/test_proxy-wide.py
  14. 2 0
      test/test_debug_endpoint/test_global.py
  15. 2 0
      test/test_debug_endpoint/test_per_container.py
  16. 0 3
      test/test_default-host.py
  17. 0 3
      test/test_enable_http_on_missing_cert.py
  18. 0 3
      test/test_host-network-mode/test_host-network-mode.py
  19. 0 3
      test/test_host-network-mode/test_proxy-host-network-mode.py
  20. 0 2
      test/test_htpasswd/test_htpasswd_regex_virtual_host.py
  21. 0 2
      test/test_htpasswd/test_htpasswd_virtual_host.py
  22. 0 2
      test/test_htpasswd/test_htpasswd_virtual_path.py
  23. 1 1
      test/test_http2/test_http2_global_disabled.py
  24. 3 3
      test/test_http3/test_http3_global_disabled.py
  25. 3 3
      test/test_http3/test_http3_global_enabled.py
  26. 3 3
      test/test_http3/test_http3_vhost.py
  27. 0 2
      test/test_internal/test_internal-per-vhost.py
  28. 0 2
      test/test_internal/test_internal-per-vpath.py
  29. 0 3
      test/test_ipv6/test_ipv6.py
  30. 0 3
      test/test_ipv6/test_ipv6_prefer_ipv4_network.py
  31. 0 3
      test/test_ipv6/test_ipv6_prefer_ipv6_network.py
  32. 1 1
      test/test_loadbalancing.py
  33. 0 2
      test/test_logs/test_log_disabled.py
  34. 0 2
      test/test_logs/test_log_format.py
  35. 0 2
      test/test_logs/test_log_json.py
  36. 0 2
      test/test_logs/test_log_json_format.py
  37. 0 3
      test/test_multiple-hosts.py
  38. 0 2
      test/test_multiple-networks.py
  39. 0 3
      test/test_multiports/test_multiports-base-json.py
  40. 0 3
      test/test_multiports/test_multiports-base-yaml.py
  41. 0 1
      test/test_multiports/test_multiports-invalid-syntax.py
  42. 0 1
      test/test_multiports/test_multiports-merge.py
  43. 0 1
      test/test_ports/test_VIRTUAL_PORT-single-different-from-single-port.py
  44. 0 3
      test/test_ports/test_VIRTUAL_PORT.py
  45. 0 3
      test/test_ports/test_default-80.py
  46. 0 3
      test/test_ports/test_single-port-not-80.py
  47. 0 3
      test/test_raw-ip-vhost.py
  48. 0 2
      test/test_server-down/test_load-balancing.py
  49. 0 2
      test/test_server-down/test_no-server-down.py
  50. 0 2
      test/test_server-down/test_server-down.py
  51. 1 0
      test/test_ssl/test_cert_selection.py
  52. 0 3
      test/test_ssl/test_hsts.py
  53. 1 0
      test/test_ssl/test_https_port.py
  54. 0 4
      test/test_ssl/test_nohttp.py
  55. 1 0
      test/test_ssl/test_nohttps.py
  56. 0 3
      test/test_ssl/test_noredirect.py
  57. 1 0
      test/test_ssl/test_virtual_path.py
  58. 2 1
      test/test_trust-downstream-proxy/test_default.py
  59. 2 1
      test/test_trust-downstream-proxy/test_disabled.py
  60. 2 1
      test/test_trust-downstream-proxy/test_enabled.py
  61. 0 1
      test/test_upstream-name/test_predictable-name.py
  62. 0 1
      test/test_upstream-name/test_sha1-name.py
  63. 3 1
      test/test_vhost-in-multiple-networks.py
  64. 1 0
      test/test_virtual-path/test_custom_conf.py
  65. 0 2
      test/test_virtual-path/test_forwarding.py
  66. 0 2
      test/test_virtual-path/test_location_precedence.py
  67. 1 0
      test/test_virtual-path/test_virtual_paths.py

+ 48 - 30
test/conftest.py

@@ -1,4 +1,5 @@
 import contextlib
+import errno
 import logging
 import os
 import re
@@ -9,13 +10,12 @@ import time
 from typing import List
 
 import backoff
-import docker
+import docker.errors
 import pytest
 import requests
-from _pytest._code.code import ReprExceptionInfo
 from packaging.version import Version
 from docker.models.containers import Container
-from requests.packages.urllib3.util.connection import HAS_IPV6
+
 
 logging.basicConfig(level=logging.INFO)
 logging.getLogger('backoff').setLevel(logging.INFO)
@@ -40,6 +40,24 @@ test_container = 'nginx-proxy-pytest'
 #
 ###############################################################################
 
+def system_has_ipv6() -> bool:
+    # See https://stackoverflow.com/a/66249915
+    _ADDR_NOT_AVAIL = {errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT}
+    _ADDR_IN_USE = {errno.EADDRINUSE}
+
+    if not socket.has_ipv6:
+        return False
+    try:
+        with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
+            sock.bind(("::1", 0))
+        return True
+    except OSError as e:
+        if e.errno in _ADDR_NOT_AVAIL:
+            return False
+        if e.errno in _ADDR_IN_USE:
+            return True
+        raise
+
 @contextlib.contextmanager
 def ipv6(force_ipv6=True):
     """
@@ -59,10 +77,10 @@ def ipv6(force_ipv6=True):
     FORCE_CONTAINER_IPV6 = False
 
 
-class requests_for_docker(object):
+class RequestsForDocker(object):
     """
     Proxy for calling methods of the requests module.
-    When a HTTP response failed due to HTTP Error 404 or 502, retry a few times.
+    When an HTTP response failed due to HTTP Error 404 or 502, retry a few times.
     Provides method `get_conf` to extract the nginx-proxy configuration content.
     """
     def __init__(self):
@@ -99,43 +117,43 @@ class requests_for_docker(object):
     def get(self, *args, **kwargs):
         with ipv6(kwargs.pop('ipv6', False)):
             @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
-            def _get(*args, **kwargs):
-                return self.session.get(*args, **kwargs)
+            def _get(*_args, **_kwargs):
+                return self.session.get(*_args, **_kwargs)
             return _get(*args, **kwargs)
 
     def post(self, *args, **kwargs):
         with ipv6(kwargs.pop('ipv6', False)):
             @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
-            def _post(*args, **kwargs):
-                return self.session.post(*args, **kwargs)
+            def _post(*_args, **_kwargs):
+                return self.session.post(*_args, **_kwargs)
             return _post(*args, **kwargs)
 
     def put(self, *args, **kwargs):
         with ipv6(kwargs.pop('ipv6', False)):
             @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
-            def _put(*args, **kwargs):
-                return self.session.put(*args, **kwargs)
+            def _put(*_args, **_kwargs):
+                return self.session.put(*_args, **_kwargs)
             return _put(*args, **kwargs)
 
     def head(self, *args, **kwargs):
         with ipv6(kwargs.pop('ipv6', False)):
             @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
-            def _head(*args, **kwargs):
-                return self.session.head(*args, **kwargs)
+            def _head(*_args, **_kwargs):
+                return self.session.head(*_args, **_kwargs)
             return _head(*args, **kwargs)
 
     def delete(self, *args, **kwargs):
         with ipv6(kwargs.pop('ipv6', False)):
             @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
-            def _delete(*args, **kwargs):
-                return self.session.delete(*args, **kwargs)
+            def _delete(*_args, **_kwargs):
+                return self.session.delete(*_args, **_kwargs)
             return _delete(*args, **kwargs)
 
     def options(self, *args, **kwargs):
         with ipv6(kwargs.pop('ipv6', False)):
             @backoff.on_predicate(backoff.constant, lambda r: r.status_code in (404, 502), interval=.3, max_tries=30, jitter=None)
-            def _options(*args, **kwargs):
-                return self.session.options(*args, **kwargs)
+            def _options(*_args, **_kwargs):
+                return self.session.options(*_args, **_kwargs)
             return _options(*args, **kwargs)
 
     def __getattr__(self, name):
@@ -150,7 +168,7 @@ def container_ip(container: Container):
     """
     global FORCE_CONTAINER_IPV6
     if FORCE_CONTAINER_IPV6:
-        if not HAS_IPV6:
+        if not system_has_ipv6():
             pytest.skip("This system does not support IPv6")
         ip = container_ipv6(container)
         if ip == '':
@@ -200,11 +218,11 @@ def nginx_proxy_dns_resolver(domain_name):
     if 'nginx-proxy' in domain_name:
         nginxproxy_containers = docker_client.containers.list(filters={"status": "running", "ancestor": "nginxproxy/nginx-proxy:test"})
         if len(nginxproxy_containers) == 0:
-            log.warn(f"no container found from image nginxproxy/nginx-proxy:test while resolving {domain_name!r}")
+            log.warning(f"no container found from image nginxproxy/nginx-proxy:test while resolving {domain_name!r}")
             exited_nginxproxy_containers = docker_client.containers.list(filters={"status": "exited", "ancestor": "nginxproxy/nginx-proxy:test"})
             if len(exited_nginxproxy_containers) > 0:
                 exited_nginxproxy_container_logs = exited_nginxproxy_containers[0].logs()
-                log.warn(f"nginxproxy/nginx-proxy:test container might have exited unexpectedly. Container logs: " + "\n" + exited_nginxproxy_container_logs.decode())
+                log.warning(f"nginxproxy/nginx-proxy:test container might have exited unexpectedly. Container logs: " + "\n" + exited_nginxproxy_container_logs.decode())
             return
         nginxproxy_container = nginxproxy_containers[0]
         ip = container_ip(nginxproxy_container)
@@ -231,7 +249,7 @@ def docker_container_dns_resolver(domain_name):
     try:
         container = docker_client.containers.get(container_name)
     except docker.errors.NotFound:
-        log.warn(f"container named {container_name!r} not found while resolving {domain_name!r}")
+        log.warning(f"container named {container_name!r} not found while resolving {domain_name!r}")
         return
     log.debug(f"container {container.name!r} found ({container.short_id})")
 
@@ -252,9 +270,9 @@ def monkey_patch_urllib_dns_resolver():
         logging.getLogger('DNS').debug(f"resolving domain name {repr(args)}")
         _args = list(args)
 
-        # Fail early when querying IP directly and it is forced ipv6 when not supported,
+        # Fail early when querying IP directly, and it is forced ipv6 when not supported,
         # Otherwise a pytest container not using the host network fails to pass `test_raw-ip-vhost`.
-        if FORCE_CONTAINER_IPV6 and not HAS_IPV6:
+        if FORCE_CONTAINER_IPV6 and not system_has_ipv6():
             pytest.skip("This system does not support IPv6")
 
         # custom DNS resolvers
@@ -371,7 +389,7 @@ def connect_to_network(network):
         try:
             my_container = docker_client.containers.get(test_container)
         except docker.errors.NotFound:
-            logging.warn(f"container {test_container} not found")
+            logging.warning(f"container {test_container} not found")
             return
 
         # figure out our container networks
@@ -399,7 +417,7 @@ def disconnect_from_network(network=None):
         try:
             my_container = docker_client.containers.get(test_container)
         except docker.errors.NotFound:
-            logging.warn(f"container {test_container} not found")
+            logging.warning(f"container {test_container} not found")
             return
 
         # figure out our container networks
@@ -427,6 +445,7 @@ def connect_to_all_networks():
 
 class DockerComposer(contextlib.AbstractContextManager):
     def __init__(self):
+        self._networks = None
         self._docker_compose_file = None
 
     def __exit__(self, *exc_info):
@@ -498,7 +517,7 @@ def nginxproxy():
     """
     Provides the `nginxproxy` object that can be used in the same way the requests module is:
 
-    r = nginxproxy.get("http://foo.com")
+    r = nginxproxy.get("https://foo.com")
 
     The difference is that in case an HTTP requests has status code 404 or 502 (which mostly
     indicates that nginx has just reloaded), we retry up to 30 times the query.
@@ -507,7 +526,7 @@ def nginxproxy():
     made against containers to use the containers IPv6 address when set to `True`. If IPv6 is not
     supported by the system or docker, that particular test will be skipped.
     """
-    yield requests_for_docker()
+    yield RequestsForDocker()
 
 
 @pytest.fixture()
@@ -526,11 +545,10 @@ def acme_challenge_path():
 # pytest hook to display additionnal stuff in test report
 def pytest_runtest_logreport(report):
     if report.failed:
-        if isinstance(report.longrepr, ReprExceptionInfo):
             test_containers = docker_client.containers.list(all=True, filters={"ancestor": "nginxproxy/nginx-proxy:test"})
             for container in test_containers:
-                report.longrepr.addsection('nginx-proxy logs', container.logs())
-                report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container))
+                report.longrepr.addsection('nginx-proxy logs', container.logs().decode())
+                report.longrepr.addsection('nginx-proxy conf', get_nginx_conf_from_container(container).decode())
 
 
 # Py.test `incremental` marker, see http://stackoverflow.com/a/12579625/107049

+ 1 - 0
test/requirements/python-requirements.txt

@@ -1,4 +1,5 @@
 backoff==2.2.1
 docker==7.1.0
+packaging==24.2
 pytest==8.3.4
 requests==2.32.3

+ 0 - 2
test/test_DOCKER_HOST_unix_socket.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_unknown_virtual_host(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/port")
     assert r.status_code == 503

+ 0 - 3
test/test_acme_http_challenge_location/test_acme_challenge_location_disabled.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_redirect_acme_challenge_location_disabled(docker_compose, nginxproxy, acme_challenge_path):
     r = nginxproxy.get(
         f"http://web1.nginx-proxy.tld/{acme_challenge_path}",

+ 0 - 3
test/test_acme_http_challenge_location/test_acme_challenge_location_enabled_is_default.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_redirect_acme_challenge_location_enabled(docker_compose, nginxproxy, acme_challenge_path):
     r = nginxproxy.get(
         f"http://web1.nginx-proxy.tld/{acme_challenge_path}",

+ 0 - 3
test/test_acme_http_challenge_location/test_acme_challenge_location_legacy.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_redirect_acme_challenge_location_legacy(docker_compose, nginxproxy, acme_challenge_path):
     r = nginxproxy.get(
         f"http://web1.nginx-proxy.tld/{acme_challenge_path}",

+ 4 - 2
test/test_build.py

@@ -1,11 +1,13 @@
 """
 Test that nginx-proxy-tester can build successfully
 """
-import pytest
-import docker
 import re
 import os
 
+import docker
+import pytest
+
+
 client = docker.from_env()
 
 @pytest.fixture(scope = "session")

+ 0 - 1
test/test_custom-error-page/test_custom-error-page.py

@@ -1,4 +1,3 @@
-import pytest
 import re
 
 

+ 0 - 2
test/test_custom/test_defaults-location.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_custom_default_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/")
     assert r.status_code == 503

+ 0 - 2
test/test_custom/test_defaults.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/")
     assert r.status_code == 503

+ 0 - 2
test/test_custom/test_location-per-vhost.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/")
     assert r.status_code == 503

+ 0 - 2
test/test_custom/test_per-vhost.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/")
     assert r.status_code == 503

+ 0 - 2
test/test_custom/test_proxy-wide.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_custom_conf_does_not_apply_to_unknown_vhost(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/")
     assert r.status_code == 503

+ 2 - 0
test/test_debug_endpoint/test_global.py

@@ -1,6 +1,8 @@
 import json
+
 import pytest
 
+
 def test_debug_endpoint_is_enabled_globally(docker_compose, nginxproxy):
     r = nginxproxy.get("http://enabled.debug.nginx-proxy.example/nginx-proxy-debug")
     assert r.status_code == 200

+ 2 - 0
test/test_debug_endpoint/test_per_container.py

@@ -1,6 +1,8 @@
 import json
+
 import pytest
 
+
 def test_debug_endpoint_is_disabled_globally(docker_compose, nginxproxy):
     r = nginxproxy.get("http://disabled1.debug.nginx-proxy.example/nginx-proxy-debug")
     assert r.status_code == 404 

+ 0 - 3
test/test_default-host.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_fallback_on_default(docker_compose, nginxproxy):
     r = nginxproxy.get("http://unknown.nginx-proxy.tld/port")
     assert r.status_code == 200

+ 0 - 3
test/test_enable_http_on_missing_cert.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_nohttp_missing_cert_disabled(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nohttp-missing-cert-disabled.nginx-proxy.tld/", allow_redirects=False)
     assert r.status_code == 503

+ 0 - 3
test/test_host-network-mode/test_host-network-mode.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_forwards_to_bridge_network_container(docker_compose, nginxproxy):
     r = nginxproxy.get("http://bridge-network.nginx-proxy.tld/port")
     assert r.status_code == 200   

+ 0 - 3
test/test_host-network-mode/test_proxy-host-network-mode.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_forwards_to_host_network_container_1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://host-network-1.nginx-proxy.tld:8888/port")
     assert r.status_code == 200

+ 0 - 2
test/test_htpasswd/test_htpasswd_regex_virtual_host.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_htpasswd_regex_virtual_host_is_restricted(docker_compose, nginxproxy):
     r = nginxproxy.get("http://regex.htpasswd.nginx-proxy.example/port")
     assert r.status_code == 401

+ 0 - 2
test/test_htpasswd/test_htpasswd_virtual_host.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_htpasswd_virtual_host_is_restricted(docker_compose, nginxproxy):
     r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/port")
     assert r.status_code == 401

+ 0 - 2
test/test_htpasswd/test_htpasswd_virtual_path.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_htpasswd_virtual_path_is_restricted(docker_compose, nginxproxy):
     r = nginxproxy.get("http://htpasswd.nginx-proxy.tld/foo/port")
     assert r.status_code == 401

+ 1 - 1
test/test_http2/test_http2_global_disabled.py

@@ -1,6 +1,6 @@
-import pytest
 import re
 
+
 def test_http2_global_disabled_config(docker_compose, nginxproxy):
     conf = nginxproxy.get_conf().decode('ASCII')
     r = nginxproxy.get("http://http2-global-disabled.nginx-proxy.tld")

+ 3 - 3
test/test_http3/test_http3_global_disabled.py

@@ -1,8 +1,8 @@
-import pytest
 import re
 
-    #Python Requests is not able to do native http3 requests. 
-    #We only check for directives which should enable http3.
+
+# Python Requests is not able to do native http3 requests.
+# We only check for directives which should enable http3.
 
 def test_http3_global_disabled_ALTSVC_header(docker_compose, nginxproxy):
     r = nginxproxy.get("http://http3-global-disabled.nginx-proxy.tld/headers")

+ 3 - 3
test/test_http3/test_http3_global_enabled.py

@@ -1,8 +1,8 @@
-import pytest
 import re
 
-    #Python Requests is not able to do native http3 requests. 
-    #We only check for directives which should enable http3.
+
+# Python Requests is not able to do native http3 requests.
+# We only check for directives which should enable http3.
 
 def test_http3_global_enabled_ALTSVC_header(docker_compose, nginxproxy):
     r = nginxproxy.get("http://http3-global-enabled.nginx-proxy.tld/headers")

+ 3 - 3
test/test_http3/test_http3_vhost.py

@@ -1,8 +1,8 @@
-import pytest
 import re
 
-    #Python Requests is not able to do native http3 requests. 
-    #We only check for directives which should enable http3.
+
+# Python Requests is not able to do native http3 requests.
+# We only check for directives which should enable http3.
 
 def test_http3_vhost_enabled_ALTSVC_header(docker_compose, nginxproxy):
     r = nginxproxy.get("http://http3-vhost-enabled.nginx-proxy.tld/headers")

+ 0 - 2
test/test_internal/test_internal-per-vhost.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_network_web1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web1.nginx-proxy.example/port")
     assert r.status_code == 200   

+ 0 - 2
test/test_internal/test_internal-per-vpath.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_network_web1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy.example/web1/port")
     assert r.status_code == 200   

+ 0 - 3
test/test_ipv6/test_ipv6.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_unknown_virtual_host_ipv4(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/port")
     assert r.status_code == 503

+ 0 - 3
test/test_ipv6/test_ipv6_prefer_ipv4_network.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_forwards_to_ipv4_only_network(docker_compose, nginxproxy):
     r = nginxproxy.get("http://ipv4only.nginx-proxy.tld/port")
     assert r.status_code == 200   

+ 0 - 3
test/test_ipv6/test_ipv6_prefer_ipv6_network.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_forwards_to_ipv4_only_network(docker_compose, nginxproxy):
     r = nginxproxy.get("http://ipv4only.nginx-proxy.tld/port")
     assert r.status_code == 200   

+ 1 - 1
test/test_loadbalancing.py

@@ -1,6 +1,6 @@
-import pytest
 import re
 
+
 def test_loadbalance_hash(docker_compose, nginxproxy):
     conf = nginxproxy.get_conf().decode('ASCII')
     r1 = nginxproxy.get("http://loadbalance-enabled.nginx-proxy.tld")

+ 0 - 2
test/test_logs/test_log_disabled.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_log_disabled(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy.test/port")
     assert r.status_code == 200

+ 0 - 2
test/test_logs/test_log_format.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_log_format(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy.test/port")
     assert r.status_code == 200

+ 0 - 2
test/test_logs/test_log_json.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_log_json(docker_compose, nginxproxy):
     log_conf = [line for line in nginxproxy.get_conf().decode('ASCII').splitlines() if "log_format vhost escape=" in line]
     assert "{\"time_local\":\"$time_iso8601\"," in log_conf[0]

+ 0 - 2
test/test_logs/test_log_json_format.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_log_json_format(docker_compose, nginxproxy):
     log_conf = [line for line in nginxproxy.get_conf().decode('ASCII').splitlines() if "log_format vhost escape=" in line]
     assert "{\"time_local\":\"$time_iso8601\"," in log_conf[0]

+ 0 - 3
test/test_multiple-hosts.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_unknown_virtual_host_is_503(docker_compose, nginxproxy):
     r = nginxproxy.get("http://unknown.nginx-proxy.tld/port")
     assert r.status_code == 503

+ 0 - 2
test/test_multiple-networks.py

@@ -1,7 +1,5 @@
 import re
 
-import pytest
-
 
 def test_unknown_virtual_host(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy/")

+ 0 - 3
test/test_multiports/test_multiports-base-json.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_virtual_host_is_dropped_when_using_multiports(docker_compose, nginxproxy):
     r = nginxproxy.get("http://notskipped.nginx-proxy.tld/port")
     assert r.status_code == 200

+ 0 - 3
test/test_multiports/test_multiports-base-yaml.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_virtual_host_is_dropped_when_using_multiports(docker_compose, nginxproxy):
     r = nginxproxy.get("http://notskipped.nginx-proxy.tld/port")
     assert r.status_code == 200

+ 0 - 1
test/test_multiports/test_multiports-invalid-syntax.py

@@ -1,4 +1,3 @@
-import pytest
 import re
 
 

+ 0 - 1
test/test_multiports/test_multiports-merge.py

@@ -1,5 +1,4 @@
 import backoff
-import pytest
 
 
 def test_multiports_and_legacy_configs_should_be_merged(docker_compose, nginxproxy):

+ 0 - 1
test/test_ports/test_VIRTUAL_PORT-single-different-from-single-port.py

@@ -1,4 +1,3 @@
-import pytest
 import re
 
 

+ 0 - 3
test/test_ports/test_VIRTUAL_PORT.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_answer_is_served_from_chosen_port(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web.nginx-proxy.tld/port")
     assert r.status_code == 200

+ 0 - 3
test/test_ports/test_default-80.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_answer_is_served_from_port_80_by_default(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web.nginx-proxy.tld/port")
     assert r.status_code == 200

+ 0 - 3
test/test_ports/test_single-port-not-80.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_answer_is_served_from_exposed_port_even_if_not_80(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web.nginx-proxy.tld/port")
     assert r.status_code == 200

+ 0 - 3
test/test_raw-ip-vhost.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_raw_ipv4_vhost_forwards_to_web1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://172.20.0.4")
     assert r.status_code == 200

+ 0 - 2
test/test_server-down/test_load-balancing.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_web_has_no_server_down(docker_compose, nginxproxy):
     conf = nginxproxy.get_conf().decode('ASCII')
     r = nginxproxy.get("http://web.nginx-proxy.tld/port")

+ 0 - 2
test/test_server-down/test_no-server-down.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_web_has_no_server_down(docker_compose, nginxproxy):
     conf = nginxproxy.get_conf().decode('ASCII')
     r = nginxproxy.get("http://web.nginx-proxy.tld/port")

+ 0 - 2
test/test_server-down/test_server-down.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_web_has_server_down(docker_compose, nginxproxy):
     conf = nginxproxy.get_conf().decode('ASCII')
     r = nginxproxy.get("http://web.nginx-proxy.tld/port")

+ 1 - 0
test/test_ssl/test_cert_selection.py

@@ -1,4 +1,5 @@
 import json
+
 import pytest
 
 

+ 0 - 3
test/test_ssl/test_hsts.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_web1_HSTS_default(docker_compose, nginxproxy):
     r = nginxproxy.get("https://web1.nginx-proxy.tld/port", allow_redirects=False)
     assert "answer from port 81\n" in r.text

+ 1 - 0
test/test_ssl/test_https_port.py

@@ -1,5 +1,6 @@
 import pytest
 
+
 @pytest.mark.parametrize("subdomain", ["foo", "bar"])
 def test_web1_http_redirects_to_https(docker_compose, nginxproxy, subdomain):
     r = nginxproxy.get("http://%s.nginx-proxy.tld:8080/" % subdomain, allow_redirects=False)

+ 0 - 4
test/test_ssl/test_nohttp.py

@@ -1,7 +1,3 @@
-import pytest
-import requests
-
-
 def test_web2_http_is_connection_refused(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web2.nginx-proxy.tld/", allow_redirects=False)
     assert r.status_code == 503

+ 1 - 0
test/test_ssl/test_nohttps.py

@@ -1,6 +1,7 @@
 import pytest
 from requests import ConnectionError
 
+
 def test_http_is_forwarded(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web.nginx-proxy.tld/port", allow_redirects=False)
     assert r.status_code == 200

+ 0 - 3
test/test_ssl/test_noredirect.py

@@ -1,6 +1,3 @@
-import pytest
-
-
 def test_web3_http_is_forwarded(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web3.nginx-proxy.tld/port", allow_redirects=False)
     assert r.status_code == 200

+ 1 - 0
test/test_ssl/test_virtual_path.py

@@ -1,6 +1,7 @@
 import pytest
 from requests import ConnectionError
 
+
 @pytest.mark.parametrize("path", ["web1", "web2"])
 def test_web1_http_redirects_to_https(docker_compose, nginxproxy, path):
     r = nginxproxy.get("http://www.nginx-proxy.tld/%s/port" % path, allow_redirects=False)

+ 2 - 1
test/test_trust-downstream-proxy/test_default.py

@@ -1,6 +1,7 @@
-import pytest
 import re
 
+import pytest
+
 
 @pytest.mark.parametrize('url,header,input,want', [
     ('http://web.nginx-proxy.tld/headers', 'X-Forwarded-Proto', None, 'http'),

+ 2 - 1
test/test_trust-downstream-proxy/test_disabled.py

@@ -1,6 +1,7 @@
-import pytest
 import re
 
+import pytest
+
 
 @pytest.mark.parametrize('url,header,input,want', [
     ('http://web.nginx-proxy.tld/headers', 'X-Forwarded-Proto', None, 'http'),

+ 2 - 1
test/test_trust-downstream-proxy/test_enabled.py

@@ -1,6 +1,7 @@
-import pytest
 import re
 
+import pytest
+
 
 @pytest.mark.parametrize('url,header,input,want', [
     ('http://web.nginx-proxy.tld/headers', 'X-Forwarded-Proto', None, 'http'),

+ 0 - 1
test/test_upstream-name/test_predictable-name.py

@@ -1,4 +1,3 @@
-import pytest
 import re
 
 

+ 0 - 1
test/test_upstream-name/test_sha1-name.py

@@ -1,4 +1,3 @@
-import pytest
 import re
 
 

+ 3 - 1
test/test_vhost-in-multiple-networks.py

@@ -1,7 +1,9 @@
-import pytest
 import logging
 import time
 
+import pytest
+
+
 def test_forwards_to_web1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://web1.nginx-proxy.example/port")
     assert r.status_code == 200

+ 1 - 0
test/test_virtual-path/test_custom_conf.py

@@ -1,5 +1,6 @@
 import pytest
 
+
 def test_default_root_response(docker_compose, nginxproxy):
     r = nginxproxy.get("http://nginx-proxy.test/")
     assert r.status_code == 418

+ 0 - 2
test/test_virtual-path/test_forwarding.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_root_redirects_to_web1(docker_compose, nginxproxy):
     r = nginxproxy.get("http://www.nginx-proxy.tld/port", allow_redirects=False)
     assert r.status_code == 301

+ 0 - 2
test/test_virtual-path/test_location_precedence.py

@@ -1,5 +1,3 @@
-import pytest
-
 def test_location_precedence_case1(docker_compose, nginxproxy):
     r = nginxproxy.get(f"http://foo.nginx-proxy.test/web1/port")
     assert r.status_code == 200

+ 1 - 0
test/test_virtual-path/test_virtual_paths.py

@@ -3,6 +3,7 @@ from time import sleep
 import pytest
 from docker.errors import NotFound
 
+
 @pytest.mark.parametrize("stub,expected_port", [
     ("nginx-proxy.test/web1", 81),
     ("nginx-proxy.test/web2", 82),