【发布时间】:2018-02-10 20:19:27
【问题描述】:
我正在使用 pytest 编写一些测试,其中许多具有类似的固定装置。我想将这些“全局”夹具放在一个文件中,以便可以在多个测试文件中重用它们。我的第一个想法是创建一个fixtures.py 文件,例如
import pytest
@pytest.fixture()
def my_fixture():
# do something
现在我如何在my_tests.py 中使用这个夹具?
def test_connect(my_fixture):
pass
这给出了fixture 'my_fixture' not found。我可以from fixtures import my_fixture。对于这种情况,建议的解决方案是什么?
【问题讨论】:
标签: python unit-testing pytest fixtures