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 摘要。