选择单元测试子集的nose插件
nose-picker的Python项目详细描述
nose picker是一个选择单元测试子集的插件(在django中 也一样!)
这个插件修改了nose的单元测试发现,只选择 要运行的单元测试。通过传入--total-processes参数,您可以选择 要运行的分母(上面的n)。那--which-process 参数控制要运行该子集的哪个部分,因此如果有5个子集,则 可以选择0、1、2、3或4。
它是如何工作的?很简单!它散列nose的文件名 运行时,将模除以n,然后查看此文件是否为“its”。 非常简单,但它允许您运行这些nose picker中的多个 并行运行,每个运行单元测试的单独子集!
动机
nose多进程插件在运行时接管测试运行程序,因此 不适用于需要自定义测试运行程序的环境。 nose picker让您保留测试运行程序!
安装
通过pip:
pip install --user nose-picker
多进程脚本示例
例如:
def main(): num_processes = int(multiprocessing.cpu_count() * 2.5) tests = [] for i in range(num_processes): test_command = TEST_CMD_TEMPLATE % ( i, num_processes, ) tests.append(TestWatcher(test_command)) returncode = 0 for test_watcher in tests: test_watcher.join() if test_watcher.returncode > 0: returncode += test_watcher.returncode for line in test_watcher.stderr.splitlines(): if not ( line.endswith(' ... ok') or '... SKIP' in line ): sys.stderr.write(line + '\n') return returncode class TestWatcher(threading.Thread): def __init__(self, command): super(TestWatcher, self).__init__() self.command = command self.stdout = '' self.stderr = '' self.start() self.returncode = 0 def run(self): p = subprocess.Popen( self.command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) self.stdout, self.stderr = p.communicate() self.returncode = p.returncode
许可证
nose picker版权所有2014 EventBrite和贡献者,由 在BSD样式许可下提供;有关详细信息,请参阅许可。