假设我有这样一个测试套件:
class SafeTests(unittest.TestCase):
# snip 20 test functions
class BombTests(unittest.TestCase):
# snip 10 different test cases
我目前正在做以下工作:
^{pr2}$我有个大问题,还有一点很有趣
我有大量不同的应用程序公开这些测试 套房通过入口。在
我想能够聚合这些自定义测试跨所有安装 所以我不能使用一个聪明的命名约定。我不 尤其是关心这些通过入口点暴露出来,但是我 是否关心是否能够在中跨应用程序运行测试 站点包。(不只是导入。。。每个模块。)
我不在乎维持当前对
unittest.TestCase
,破坏依赖关系实际上是一个目标。在
编辑这是为了确认@Oleksiy关于将参数传递给
nose.run
实际上有一些注意事项。在
不起作用的事情:
这种脆弱是荒谬的,如果你有改善它的想法,我欢迎 评论,或者我设置 a github repo with my experiments trying to get this to work。在
除此之外,下面的工作,包括多个项目 安装到站点包中:
#!python
import importlib, os, sys
import nose
def runtests():
modnames = []
dirs = set()
for modname in sys.argv[1:]:
modnames.append(modname)
mod = importlib.import_module(modname)
fname = mod.__file__
dirs.add(os.path.dirname(fname))
modnames = list(dirs) + modnames
nose.run(argv=modnames)
if __name__ == '__main__':
runtests()
{right当保存到cd3}文件中时:
runtests.py project.tests otherproject.tests
对于nose,您可以同时使用attribute插件选择要运行的测试,这对于选择要运行的测试非常有用。我将保留这两个测试并为它们分配属性:
对于您的生产代码,我只需要使用
^{pr2}$nosetests -a safe
调用nose,或者在您的os生产测试环境中设置NOSE_ATTR=safe
,或者调用nose对象上的run方法,根据您的-a
命令行选项在python中本机运行它:最后,如果由于某种原因您的测试没有被发现,您可以使用
@istest
属性(from nose.tools import istest
)显式地将它们标记为test如果你的问题是,“如何让pytest‘看到’一个测试?”,则需要在每个测试文件和每个测试用例(即函数)前添加“test”。然后,只需在pytest命令行上传递要搜索的目录,它将递归地搜索匹配“test”的文件_三十、 是的,从中收集“test_XXX”函数并运行它们。在
至于文档,您可以尝试启动here.
如果您不喜欢默认的pytest测试集合方法,可以使用方向here.对其进行自定义
结果弄得一团糟:鼻子几乎只使用} )
所以既然我想从一个任意的python对象装载东西,我
似乎需要自己写一个算出来要用什么样的加载函数。在
TestLoader.load_tests_from_names
函数(它是唯一的函数在 ^{此外,还要正确地使
nosetests
脚本正常工作 我需要进口大量的东西。我一点也不确定 是做事最好的方式,甚至不是那种。但这是一个脱光 对我有用的示例(无错误检查,更详细):相关问题 更多 >
编程相关推荐