Commit a7e182f9 by Bjorn Neergaard

tests: properly use and cleanup httpretty

parent 27531c1f
...@@ -275,12 +275,8 @@ def git_mock(mocker: MockerFixture) -> None: ...@@ -275,12 +275,8 @@ def git_mock(mocker: MockerFixture) -> None:
@pytest.fixture @pytest.fixture
def http() -> Iterator[type[httpretty.httpretty]]: def http() -> Iterator[type[httpretty.httpretty]]:
httpretty.reset() httpretty.reset()
httpretty.enable(allow_net_connect=False) with httpretty.enabled(allow_net_connect=False):
yield httpretty
yield httpretty
httpretty.activate()
httpretty.reset()
@pytest.fixture @pytest.fixture
......
...@@ -215,7 +215,7 @@ def test_authenticator_request_retries_on_exception( ...@@ -215,7 +215,7 @@ def test_authenticator_request_retries_on_exception(
raise requests.exceptions.ConnectionError("Disconnected") raise requests.exceptions.ConnectionError("Disconnected")
return [200, response_headers, content] return [200, response_headers, content]
httpretty.register_uri(httpretty.GET, sdist_uri, body=callback) http.register_uri(httpretty.GET, sdist_uri, body=callback)
authenticator = Authenticator(config, NullIO()) authenticator = Authenticator(config, NullIO())
response = authenticator.request("get", sdist_uri) response = authenticator.request("get", sdist_uri)
...@@ -233,7 +233,7 @@ def test_authenticator_request_raises_exception_when_attempts_exhausted( ...@@ -233,7 +233,7 @@ def test_authenticator_request_raises_exception_when_attempts_exhausted(
def callback(*_: Any, **___: Any) -> None: def callback(*_: Any, **___: Any) -> None:
raise requests.exceptions.ConnectionError(str(uuid.uuid4())) raise requests.exceptions.ConnectionError(str(uuid.uuid4()))
httpretty.register_uri(httpretty.GET, sdist_uri, body=callback) http.register_uri(httpretty.GET, sdist_uri, body=callback)
authenticator = Authenticator(config, NullIO()) authenticator = Authenticator(config, NullIO())
with pytest.raises(requests.exceptions.ConnectionError): with pytest.raises(requests.exceptions.ConnectionError):
...@@ -271,7 +271,7 @@ def test_authenticator_request_retries_on_status_code( ...@@ -271,7 +271,7 @@ def test_authenticator_request_retries_on_status_code(
) -> list[int | dict | str]: ) -> list[int | dict | str]:
return [status, response_headers, content] return [status, response_headers, content]
httpretty.register_uri(httpretty.GET, sdist_uri, body=callback) http.register_uri(httpretty.GET, sdist_uri, body=callback)
authenticator = Authenticator(config, NullIO()) authenticator = Authenticator(config, NullIO())
with pytest.raises(requests.exceptions.HTTPError) as excinfo: with pytest.raises(requests.exceptions.HTTPError) as excinfo:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment