首页 > 解决方案 > 如何使用 Pytest 从 Firebase 测试用户的可选信息

问题描述

我在 Firebase 上启用了匿名登录方法,因此我的用户集合中有一些不需要的信息。我想知道如何使用 pytest 和参数化进行测试。

我的用户集合将如下所示:

{
    "users":[
        {
            "id": "",
            "name": "" || null,
            "email": "" || null,
            "password": "" || null,
            "birthdate": Long/Number || null,
            "parents_contact": "" || null,
        }
    ]
}

匿名登录方式只需要id。

我很难写这样的东西:

@pytest.mark.parametrize(
    "id, data, status_code",
    [
        [1, {}, 200],
        [1, {"name": "John"}, 200],
        [1, {"name": "John", "email": "john@mail.com"}, 200],
        [1, {"name": "John", "email": "john@mail.com", "password": "john123"}, 200],
        ...
    ],
)

这是使用 pytest 和的正确方法parametrize吗?

标签: python-3.xfirebasepytestpyrebase

解决方案


推荐阅读