def test_check_proxy_env_vars( http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY, no_proxy, NO_PROXY ): """Test pytest_localstack.utils.check_proxy_env_vars.""" with utils.mock.patch.dict(os.environ): # mock.patch.dict can't delete keys. # Patch os.environ manually. _set_env_var("http_proxy", http_proxy) _set_env_var("https_proxy", https_proxy) _set_env_var("HTTP_PROXY", HTTP_PROXY) _set_env_var("HTTPS_PROXY", HTTPS_PROXY) _set_env_var("no_proxy", no_proxy) _set_env_var("NO_PROXY", NO_PROXY) settings_match = ( ((http_proxy or HTTP_PROXY) == (HTTP_PROXY or http_proxy)) and ((https_proxy or HTTPS_PROXY) == (HTTPS_PROXY or https_proxy)) and ((no_proxy or NO_PROXY) == (NO_PROXY or no_proxy)) ) has_http_proxy = bool(_get_env_var("http_proxy")) has_https_proxy = bool(_get_env_var("https_proxy")) good_no_proxy = "127.0.0.1" in _get_env_var("no_proxy") if (has_http_proxy or has_https_proxy) and not ( settings_match and good_no_proxy ): with pytest.raises(UserWarning): utils.check_proxy_env_vars() else: utils.check_proxy_env_vars()
def test_check_proxy_env_vars(http_proxy, https_proxy, HTTP_PROXY, HTTPS_PROXY, no_proxy, NO_PROXY): """Test pytest_localstack.utils.check_proxy_env_vars.""" with mock.patch.dict(os.environ): # mock.patch.dict can't delete keys. # Patch os.environ manually. _set_env_var("http_proxy", http_proxy) _set_env_var("https_proxy", https_proxy) _set_env_var("HTTP_PROXY", HTTP_PROXY) _set_env_var("HTTPS_PROXY", HTTPS_PROXY) _set_env_var("no_proxy", no_proxy) _set_env_var("NO_PROXY", NO_PROXY) settings_match = ( ((http_proxy or HTTP_PROXY) == (HTTP_PROXY or http_proxy)) and ((https_proxy or HTTPS_PROXY) == (HTTPS_PROXY or https_proxy)) and ((no_proxy or NO_PROXY) == (NO_PROXY or no_proxy))) has_http_proxy = bool(_get_env_var("http_proxy")) has_https_proxy = bool(_get_env_var("https_proxy")) good_no_proxy = "127.0.0.1" in _get_env_var("no_proxy") if (has_http_proxy or has_https_proxy) and not (settings_match and good_no_proxy): with pytest.raises(UserWarning): utils.check_proxy_env_vars() else: utils.check_proxy_env_vars()
def _make_session(docker_client, *args, **kwargs): utils.check_proxy_env_vars() if docker_client is None: docker_client = docker.from_env() try: docker_client.ping() # Check connectivity except docker.errors.APIError: pytest.fail("Could not connect to Docker.") _session = session.LocalstackSession(docker_client, *args, **kwargs) _session.start(timeout=_start_timeout) try: yield _session finally: _session.stop(timeout=_stop_timeout)
def _make_session(docker_client, *args, **kwargs): if pytest.config.getoption("--no-localstack"): pytest.skip("skipping because --no-localstack is set") utils.check_proxy_env_vars() if docker_client is None: docker_client = docker.from_env() try: docker_client.ping() # Check connectivity except docker.errors.APIError: pytest.fail("Could not connect to Docker.") _session = session.LocalstackSession(docker_client, *args, **kwargs) start_timeout = pytest.config.getoption("--localstack-start-timeout") stop_timeout = pytest.config.getoption("--localstack-stop-timeout") _session.start(timeout=start_timeout) try: yield _session finally: _session.stop(timeout=stop_timeout)
def _make_session(docker_client, *args, **kwargs): if pytest.config.getoption("--no-localstack"): pytest.skip("skipping because --no-localstack is set") utils.check_proxy_env_vars() if docker_client is None: docker_client = docker.from_env() try: docker_client.ping() # Check connectivity except docker.errors.APIError: pytest.fail("Could not connect to Docker.") _session = session.LocalstackSession(docker_client, *args, **kwargs) start_timeout = pytest.config.getoption("--localstack-start-timeout") stop_timeout = pytest.config.getoption("--localstack-stop-timeout") _session.start(timeout=start_timeout) try: yield _session finally: _session.stop(timeout=stop_timeout)