File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change 1111import warnings
1212from dataclasses import dataclass , field
1313from functools import lru_cache
14+ from http .client import HTTPException
1415from importlib .metadata import PackageNotFoundError , distribution , version
1516from pathlib import Path
1617from typing import Any
@@ -330,7 +331,7 @@ def get_version_warning() -> str:
330331 data = json .load (url )
331332 with open (cache_file , "w" , encoding = "utf-8" ) as f :
332333 json .dump (data , f )
333- except (URLError , HTTPError ) as exc : # pragma: no cover
334+ except (URLError , HTTPError , HTTPException ) as exc : # pragma: no cover
334335 _logger .debug (
335336 "Unable to fetch latest version from %s due to: %s" ,
336337 release_url ,
Original file line number Diff line number Diff line change 55import subprocess
66import sys
77import time
8+ from http .client import RemoteDisconnected
89from pathlib import Path
910
1011import pytest
@@ -92,6 +93,15 @@ def test_get_version_warning_no_pip(mocker: MockerFixture) -> None:
9293 assert get_version_warning () == ""
9394
9495
96+ def test_get_version_warning_remote_disconnect (mocker : MockerFixture ) -> None :
97+ """Test that we can handle remote disconnect when fetching release url."""
98+ mocker .patch ("urllib.request.urlopen" , side_effect = RemoteDisconnected )
99+ try :
100+ get_version_warning ()
101+ except RemoteDisconnected :
102+ pytest .fail ("Failed to handle a remote disconnect" )
103+
104+
95105@pytest .mark .parametrize (
96106 ("lintable" ),
97107 (
You can’t perform that action at this time.
0 commit comments