`__module__` is not defined, seeming to contradict the Python Data Model.
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
The __module__ variable might not be defined.
This is an update to the original bug post. After some investigation this doesn't seem like a bug in unittest. Here's a simple test case that shows a situation where __module__ is not defined:
test_str = """
class MyClass:
pass
Derived = type("Derived", (MyClass,), {})
"""
test_ns = {}
exec(test_str, test_ns)
print("__module__ exists:", hasattr(test_ns["Derived"], "__module__"))
print("Module for drived:", test_ns["Derived"].__module__)
The original bug post is below:
The default test loader depends on __module__ being present. In rare cases it may not be. I encountered a crash when running unit tests using a Jupyter cell magic. The line should probably be:
fullName = f'%s.%s.%s' % (
testCaseClass.__module__ if hasattr(testCaseClass, "__module__") else "None", testCaseClass.__qualname__, attrname
)
This problem has cropped up in bug reports for other projects. For example:
https://github.com/ray-project/ray/issues/4758
https://gitlab.orekit.org/orekit-labs/python-wrapper/-/issues/411
Thank you for the wonderful work!
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-120957
- gh-120979
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Lib/unittest/loader.py#L220 開始,在 Python 3.12 上執行提供的 exec 重現程式碼。檢查預設測試載入器對沒有 module 的類別的處理,然後在 unittest 測試套件中新增或更新回歸測試。當載入器不再崩潰且回歸案例通過時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- testing-qa
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100