Python 的单元测试可以像鼻子一样并行测试吗? [英] Can Python's unittest test in parallel, like nose can?

查看:48
本文介绍了Python 的单元测试可以像鼻子一样并行测试吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python 的 NOSE 测试框架具有并行运行多个测试的概念.

Python's NOSE testing framework has the concept of running multiple tests in parallel.

这样做的目的不是为了测试代码中的并发性,而是为了让没有副作用、没有排序问题、没有外部依赖"的代码运行得更快.性能提升来自于访问不同设备时的并发 I/O 等待、更好地利用多 CPU/内核以及并行运行 time.sleep() 语句.

The purpose of this is not to test concurrency in the code, but to make tests for code that has "no side-effects, no ordering issues, and no external dependencies" run faster. The performance gain comes from concurrent I/O waits when they are accessing different devices, better use of multi CPUs/cores, and by running time.sleep() statements in parallel.

我相信 Python 的 unittest 测试框架可以通过插件 Test Runner 完成同样的事情.

I believe the same thing could be done with Python's unittest testing framework, by having a plugin Test Runner.

有没有人对这样的野兽有任何经验,他们可以提出任何建议吗?

Has anyone had any experience with such a beast, and can they make any recommendations?

推荐答案

Python unittest 的内置测试运行程序不能并行运行测试.写一个这样做可能不会太难.我自己写的只是为了重新格式化输出和每次测试的时间.这可能需要每天 1/2.我认为您可以将使用的 TestSuite 类替换为使用多进程的派生类,而不会有太多麻烦.

Python unittest's builtin testrunner does not run tests in parallel. It probably wouldn't be too hard write one that did. I've written my own just to reformat the output and time each test. That took maybe 1/2 a day. I think you can swap out the TestSuite class that is used with a derived one that uses multiprocess without much trouble.

这篇关于Python 的单元测试可以像鼻子一样并行测试吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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