gpt4 book ai didi

python - 从命令提示符运行单元测试

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:21 26 4
gpt4 key购买 nike

我已经创建了 python 文件和单元测试,但我不明白如何从命令提示符一次性运行所有测试。

文件结构

- py
- __init__.py
- file1.py
- file2.py
- tests
__init__.py
- test_file1.py
- test_file2.py

请告诉我相同的信息。当我尝试使用 nosetests 运行测试时,它说我

no module name file1
no module name file2

最佳答案

下面是 Nose 文档的一个片段(因为你已经标记了 nose)

nose collects tests automatically from python source files, directories and packages found in its working directory (which defaults to the current working directory). Any python source file, directory or package that matches the testMatch regular expression (by default: (?:\b|_)[Tt]est will be collected as a test (or source for collection of tests). In addition, all other packages found in the working directory will be examined for python source files or directories that match testMatch. Package discovery descends all the way down the tree, so package.tests and package.sub.tests and package.sub.sub2.tests will all be collected.

强调我的。

您可以简单地从项目的根目录运行所有测试用例:

$ cd /path/to/your/project
$ nosetests

关于python - 从命令提示符运行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37959719/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com