如何以一种可以在单个命令中运行所有测试的方式来组织python测试? [英] How to organize python test in a way that I can run all tests in a single command?

查看:111
本文介绍了如何以一种可以在单个命令中运行所有测试的方式来组织python测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我的代码采用以下树形结构进行组织:

Currently my code is organized in the following tree structure:

src/
    module1.py
    module2.py
    test_module1.py
    test_module2.py
    subpackage1/
        __init__.py
        moduleA.py
        moduleB.py
        test_moduleA.py
        test_moduleB.py

其中module*.py文件包含源代码,而test_module*.py包含相关模块的TestCase.

Where the module*.py files contains the source code and the test_module*.py contains the TestCases for the relevant module.

例如,使用以下命令,我可以运行单个文件中包含的测试:

With the following comands I can run the tests contained in a single file, for example:

$ cd src
$ nosetests test_filesystem.py
..................
----------------------------------------------------------------------
Ran 18 tests in 0.390s

OK

如何运行所有测试?我尝试使用nosetests -m 'test_.*',但是它不起作用.

How can I run all tests? I tried with nosetests -m 'test_.*' but it doesn't work.

$cd src
$ nosetests -m 'test_.*'

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

谢谢

推荐答案

如果它们都以test开头,则只需nosetest应该可以.鼻子会自动搜索以"test"开头的任何文件.

If they all begin with test then just nosetest should work. Nose automatically searches for any files beginning with 'test'.

这篇关于如何以一种可以在单个命令中运行所有测试的方式来组织python测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆