test: connection leak test test_discovery_http_is_closed is shadowed and syntactically invalid
メンテナーはふだん 1 日以内に返信
@Capstan がすでに取り組んでいます。
2026年5月31日 から。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 75/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- python
- 領域
- testing-qa
調査の方向性
tests/test_discovery.py から始め、2つの Discovery クラス定義を比較して test_discovery_http_is_closed を特定します。pytest で対象を絞った Discovery テストを実行し、その後、修正されたテストが一時 HTTP クライアントのクローズを、shadowing や AttributeError なしに検証していることを確認します。
索引モデルが issue の本文から書いたものです。
説明
Environment details
- OS type and version: Linux (gLinux / Debian based)
- Python version:
3.13.12(also affects all supported Python versions3.10+) - pip version:
26.0.1 google-api-python-clientversion:2.197.0(at commit6e471c075039dfef24e28d11658e03d5c949c7c3)
Steps to reproduce
- Look at
tests/test_discovery.pyonmain. Note that there are two separate definitions forclass Discovery(unittest.TestCase)(one at line 498 and one at line 1566). - In Python, defining a class twice in the same module causes the second definition to silently overwrite the first. This means the first
Discoveryclass—which contains the test casetest_discovery_http_is_closed—is completely dead code and is never executed bypytest. - Attempting to manually extract and execute this test case crashes immediately because
HttpMock.close()is a regular function, but the test tries to callassert_called_once()on it.
Code example
The shadowed class in tests/test_discovery.py contains this test definition:
class Discovery(unittest.TestCase):
def test_discovery_http_is_closed(self):
http = HttpMock(datafile("malformed.json"), {"status": "200"})
# build() is called without passing the 'http' mock client!
service = build("plus", "v1", credentials=mock.sentinel.credentials)
# Fails: HttpMock.close is a standard method, not a mock object
http.close.assert_called_once()
Historical Context
This bug was introduced in September 2020 by commit 98888dadf ("fix: add method to close httplib2 connections (#1038)").
That commit added test_discovery_http_is_closed by declaring a new class Discovery(unittest.TestCase) block near the top of the file, without realizing that a class Discovery(unittest.TestCase) block was already defined and active near the bottom of the file (which immediately shadowed the new test).
The Proposed Solution
- Delete the duplicate class definition at line 498.
- Restore
test_discovery_http_is_closedinside the activeDiscoveryclass (at line 1566). - Correct the test case to use standard
unittest.mock.patchonhttplib2.Httpto verify that the temporary HTTP client created bybuild()to fetch the discovery document is safely closed after initialization completes, preventing connection/socket leaks.
@mock.patch("httplib2.Http")
def test_discovery_http_is_closed(self, mock_http_class):
mock_http = mock_http_class.return_value
mock_http.request.return_value = (
httplib2.Response({"status": "200"}),
read_datafile("plus.json"),
)
service = build("plus", "v1", static_discovery=False)
mock_http.close.assert_called_once()
Stack trace
If you isolate the legacy test case and run it, it crashes immediately with an AttributeError:
AttributeError: 'function' object has no attribute 'assert_called_once'
- 主要言語
- Python
- スター
- 8.9k
- フォーク
- 2.6k
- 平均マージ
- 2日 17時間
- マージ済み PR(30日)
- 10
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
googleapis/google-api-python-client のほかの issue
-
Disable prettyPrint by default for Google Sheets API responses対応中かも @pawciobiel が 53 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
googleapis/google-api-python-client#2788 ·
メンテナーはふだん 1 日以内に返信
-
test: strict positional parameter enforcement is ignored under pytest対応中かも @Capstan が 128 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
googleapis/google-api-python-client#2755 ·
メンテナーはふだん 1 日以内に返信
-
forms for APオープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
googleapis/google-api-python-client#2830 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
googleapis/google-api-python-client#2825 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
เมตาแมสオープン
難易度 1/5 1時間未満 初心者へのやさしさ 10/100
googleapis/google-api-python-client#2824 ·
メンテナーはふだん 1 日以内に返信
googleapis/google-api-python-client の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
FuRongJun-1999/dsh-memory#65 ·
メンテナーはふだん 1 日以内に返信
-
ci needs-ac
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Ikalus1988/MisakaNet#2930 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Qiskit/qiskit-aer#2466 ·
-
area/cli
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100