python 的 unittest 无法读取到测试脚本?-灵析社区

HAO起起

目录结构如下: (image_search_engine) ╭─pon@T4GPU ~/code/work/ponponon/image_search_engine ‹master*› ╰─➤ tree testing testing ├── __init__.py ├── resource │ ├── emoji001.jpg │ ├── emoji002.jpg │ ├── emoji003.jpg │ └── s.jpg ├── test_meta.py └── test_sample.py 运行测试命令 ╰─➤ python -m unittest testing ---------------------------------------------------------------------- Ran 0 tests in 0.000s OK unittest 会读取所有 test 开头的 .py 文件,但是我的两个 test_meta.py 和 test_sample.py 居然没有被读取? 但是写成 `python -m unittest testing.test_sample` 和 `python -m unittest testing.test_meta` 是可以的,直接 `python -m unittest testing` 却不行,为什么?

阅读量:13

点赞量:0

问AI
"unit-test-discovery" (https://link.segmentfault.com/?enc=efesFPhFgZAp%2FW%2F3jJTWAQ%3D%3D.m3a0IV0EJ8AgCullw2Yoc7otmZKBJbZpabXaryF6KchIG%2Bmy1DLyaqX4uSDpWHx4mdxrwvhrE5ZQ89oh6BhDl6s0Ecy7O6l4trqE%2FPX2l6I%3D) «NoteAs a shortcut, "python -m unittest" is the equivalent of "python -m unittest discover". If you want to pass arguments to test discovery the discover sub-> command must be used explicitly.» 看文档,一旦加参数就必须用 "python -m unittest discover" 的形式才能自动查找测试文件。如果要指定目录的话,可能应该是: "python -m unittest discover testing"