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

标签 python unit-testing nose

我已经创建了 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/

相关文章:

c# - 使用最小起订量的服务模拟异步方法

python - 是否可以用现有的 Singleton 实例修补类实例?

python - Nosetests assert_equal 显然不等于 python ==

python - jinja2 模板中的列表

python - 将数据库内容与代码一起导入..

python - pyodbc执行sqlserver存储过程--用户自定义表如何传入DEFAULT参数

python - numpy.loadtxt 比 open.....readlines() 慢得多

c++ - 如何使用 googletest 失败进入断点

c# - 在实体中模拟 ICollection 属性

python - Python 中 nosetests/unittest 中测试之间的依赖关系