python / python/cpython

python 3.12.5 source install make test test_smtplib FAIL test_with_statement AND test_with_statement_QUIT_failure Connection unexpectedly closed

未關閉
#122,874 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

tests topic-email type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

Update: This describes the problem, analysis and suggested fix. Can someone modify the source test code as indicated?

Rocky 9 LINUX

  make test
		ERROR
		======================================================================
		ERROR: test_with_statement (test.test_smtplib.SMTPSimTests.test_with_statement)
		----------------------------------------------------------------------
		Traceback (most recent call last):
		File "/home/defuser/Downloads/Python-3.12.5/Lib/test/test_smtplib.py", line 1231, in test_with_statement
			code, message = smtp.noop()
                    ^^^^^^^^^^^
		...
		======================================================================
		ERROR: test_with_statement_QUIT_failure (test.test_smtplib.SMTPSimTests.test_with_statement_QUIT_failure)
		----------------------------------------------------------------------
		Traceback (most recent call last):
		File "/home/defuser/Downloads/Python-3.12.5/Lib/test/test_smtplib.py", line 1241, in test_with_statement_QUIT_failure
			smtp.noop()
			
		cd /home/defuser/Downloads/Python-3.12.5/Lib/test
		vi test_smtplib.py
			search for (one is right before the other)
				test_with_statement
				test_with_statement_QUIT_failure
				
			note 
				with smtplib.SMTP(HOST, self.port, 'localhost') as smtp:
			
			python with explanation, see https://www.geeksforgeeks.org/with-statement-in-python/
			
		IN ANOTHER TERMINAL
		cd ~/Downloads/Python-3.12.5
		find . -name "smtplib*"
			./Doc/library/smtplib.rst
			./Lib/smtplib.py
			./Lib/__pycache__/smtplib.cpython-312.pyc
		view ./Lib/smtplib.py
			search for 
				class SMTP
					note this class meets "with" requirements in https://www.geeksforgeeks.org/with-statement-in-python/
					
					def __init__(self, host='', port=0, local_hostname=None,
									timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
									source_address=None):
		RETURN to TERMINAL "vi test_smtplib.py"
			SMTP class instantiations (see test_quit_resets_greeting) use
				smtp = smtplib.SMTP(HOST, self.port,
					local_hostname='localhost' ...)
		It is PROBABLY improper to use 'local_hostname=None' in "with" statement.

SOLUTION
In methods test_with_statement and test_with_statement_QUIT_failure
change
with smtplib.SMTP(HOST, self.port) as smtp:
to
with smtplib.SMTP(HOST, self.port, 'localhost') as smtp:

make test will now work

CPython versions tested on:

3.12

Operating systems tested on:

Linux

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Lib/test/test_smtplib.py 中的 SMTPSimTests.test_with_statement 和 test_with_statement_QUIT_failure 開始,將它們的 SMTP 建構與 test_quit_resets_greeting 進行比較。在檢查提議的 localhost 引數後執行這些測試或 make test;完成的標準是兩個已回報的失敗在 Python 3.12.5 上都通過。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
testing-qa
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
58/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。