python - pytest 并行运行测试

标签 python pytest

我想并行而不是按顺序运行我的所有 pytest 测试。

我当前的设置如下:

class Test1(OtherClass):
    @pytest.mark.parametrize("activity_name", ["activity1", "activity2"])
    @pytest.mark.flaky(reruns=1)
    def test_1(self, activity_name, generate_test_id):
    """
    """

        test_id = generate_random_test_id()
        test_name = sys._getframe().f_code.co_name

        result_triggers = self.proxy(test_name, generate_test_id, test_id, activity_name)

        expected_items = ["response"]
        validate_response("triggers", result_triggers, expected_items)


    @pytest.mark.parametrize("activity_name", ["activity1", "activity2"])
    @pytest.mark.flaky(reruns=1)
    def test_2(self, activity_name, generate_test_id):
    """
    """

        #same idea...

我使用 pytest -v -s 运行我的测试。

结果是我的测试按顺序运行,这需要很长时间,因为其中一些等待来自远程服务器的响应(集成测试)。

有什么方法可以并行运行 pytest 吗?

最佳答案

你想要 pytest-xdist。我认为Qxf2解释得很好:Qxf2 on Pytest-Xdist

不过,他们的 Linux 命令行对我来说有点过于冗长了;我用:

pytest -n <NUM>

其中 是并行工作器的数量。

关于python - pytest 并行运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45733763/

相关文章:

python - pandas系列功能构成

python - 扩展 pyyaml 以像 xml ElementTree 一样查找和替换

python - 在 python 中获取列表

python - 声音回声函数Python

python - 当 pytest 测试断言查询结果 rowcount 失败时数据库操作挂起

python-3.x - python3模拟成员变量多次获取

python - python 3 中的继承和 __dict__

python - 与 pytest 并行运行单元测试?

python - 在 pytest 中,如何中止 fixture 拆卸?

python - Travis CI 和 pytest 具有多个 python 版本