jmb*_*orr 20 python unit-testing setuptools
在python单元测试方面,我是新手,但我渴望学习!我刚读过python setup.py test可以运行从unittest类派生的所有套件.我想知道我是否也可以使用setup.py来运行单个套件和/或单个测试用例,也许可以在上一个命令中添加一些修饰符python setup.py tests suitename.如果是这样,你能指点我的任何文档/例子吗?
rod*_*sou 22
你们都错了,setup.py test可以用-s同样的方式选择python -m unittest:
cd root_of_your_package
python setup.py test -s tests.TestClass.test_method
Run Code Online (Sandbox Code Playgroud)
Mar*_*ers 16
所述setup.py test转轮是相当有限的; 它只支持让您指定特定模块.使用--help开关时,会给出命令行开关的文档:
python setup.py test --help
Common commands: (see '--help-commands' for more)
[ ... cut ... ]
Options for 'test' command:
--test-module (-m) Run 'test_suite' in specified module
--test-suite (-s) Test suite to run (e.g. 'some_module.test_suite')
[ ... more cut ... ]
Run Code Online (Sandbox Code Playgroud)
因此python setup.py test -m your.package.tests.test_module会限制仅从test_module.py文件运行测试.
test实际上,所有命令都确保已经构建了egg,test_suite从setup()元数据中提取值,配置了解压缩蛋的测试加载器,然后运行该unittest.main()函数.
如果你只需要运行一个测试,已经构建了你的蛋,没有使用拉链蛋运行它,那么你也可以使用unittest命令行界面,它几乎完成其他任务:
python -m unittest yourpackage.tests.TestClass.test_method
Run Code Online (Sandbox Code Playgroud)
会指示unittest只运行一个非常具体的测试方法.