【问题标题】:How to run multiple tests at the same time in a single class using pytest?如何使用 pytest 在单个类中同时运行多个测试?
【发布时间】:2018-03-28 19:05:25
【问题描述】:

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

请提供您的意见。

【问题讨论】:

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


    【解决方案1】:

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

    不,您可以将xdist 用于一个平台并且完全符合您的描述。

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

    pytest -n <NUM>
    

    其中&lt;NUM&gt;是并行worker的数量。如果你通过like,

    pytest -n3
    

    它将并行运行 3 个测试。

    【讨论】:

    • 详细地说,xdist 可用于并行化任何一组测试,无论它们是在同一平台还是不同平台上,测试这个字符串或那个字符串,草莓味或蓝莓味.它只是启动 n 个工作人员,每当工作人员没有运行测试时,就给它一个运行测试(除非没有更多测试)。
    • @Chanda - 谢谢!那行得通。 Chlaire - 当我将 -s 与 xdist 一起使用时,我无法在日志文件中看到日志。打印语句也已停止工作。你能告诉我这个解决方案吗?
    • @Python_Novice 这是 xdist 的 pytest 问题。看看this。希望对您有所帮助。
    猜你喜欢
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多