如何使用pytest在单个类中同时运行多个测试?

时间:2017-10-17 06:57:17

标签: python-3.x selenium-webdriver parallel-processing pytest parallel-testing

我有一个3 tests的课程,我正在使用pytest运行我的测试,使用Selenium-Webdriver来执行UI操作。

class abc:
  def test_1(self):
      print("I am test_1 open browser and perform operations")
  def test_2(self):
      print("I am test_2 open browser and perform operations")
  def test_3(self):
      print("I am test_3 open browser and perform operations")

每个测试打开Chrome浏览器实例以执行一组UI操作。现在我想一次性运行上述所有测试。理想情况下pytest应该同时打开三个Chrome个浏览器实例。 (我读过xdist插件,但我认为它用于在不同平台上运行测试)

请提供您的意见。

1 个答案:

答案 0 :(得分:2)

但我认为用于在不同平台上运行测试

不,您可以将xdist用于一个平台以及您所描述的内容。

你需要做的是,你只需要在运行时给出这样的命令:

pytest -n <NUM>

其中<NUM>是并行工人的数量。如果你传递的话,

pytest -n3

它将并行运行3次测试。