unittest无法发现测试文件?如何使用unittest discover运行所有测试?

ID:21404 / 打印

unittest无法发现测试文件?如何使用unittest discover运行所有测试?

unittest 无法识别测试脚本

问题描述:
在目录结构中包含多个以 "test" 开头的 python 文件,但使用 python -m unittest testing 命令运行测试时,却无法识别这些文件。直接指定测试文件(例如 python -m unittest testing.test_sample)可以正常运行,但无法自动检测所有测试文件。

解决方法:
根据 unittest 文档,python -m unittest 命令相当于 python -m unittest discover。如果需要传入参数,则必须使用 python -m unittest discover 的形式。

对于指定目录的测试文件,正确的命令应该是:

python -m unittest discover testing

这样,unittest 就可以自动检测所有位于 "testing" 目录下的测试文件并运行测试。

上一篇: Python单元测试无法识别文件?如何使用unittest discover命令?
下一篇: 科大讯飞Websockets API连接关闭异常:如何解决帧数据包问题?

作者:admin @ 24资源网   2025-01-14

本站所有软件、源码、文章均有网友提供,如有侵权联系308410122@qq.com

与本文相关文章

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。