繁体   English   中英

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

[英]How to run multiple tests at the same time in a single class using pytest?

我有一个包含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插件,但我认为它用于在不同平台上运行测试)

请提供您的输入。

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

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

您需要做的是,您只需要在运行时发出如下命令即可:

pytest -n <NUM>

其中<NUM>是并行工作程序的数量。如果您像这样通过,

pytest -n3

它将并行运行3个测试。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM