我正在使用 py.test 在 python 中编写一些测试。

我正在使用以下装置来创建一个用户并在我的测试中使用它,然后在测试(终结器)之后将其删除:

@pytest.fixture(scope='function')
def test_user(request):
    def finalizer():
        delete_the_user()

    request.addfinalizer(finalizer)
    return user()

带有 delete_the_user()user() 两个函数,这里不详述。

问题是:我想在一些测试中使用 2 个用户。

我在这一点上没有找到任何主题(或者我可能没有使用权限关键字:/)

我试图这样称呼夹具:
    def test_function(test_user_1 = test_user, test_user_2 = test_user):
         # Test here

没有成功。

关于我应该关注什么方向的任何想法?

非常感谢 !

最佳答案

我能想到的唯一方法是:

  • 有第二个固定装置
  • 使夹具返回一个函数(但是您也必须使用夹具重构其他函数)。
  • 关于python - 在 py.test 中多次调用同一个装置,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37001586/

    10-12 14:28
    查看更多