4
我正在使用pytest编写一些测试,其中许多测试具有类似的装置。我想将这些“全局”灯具放在一个文件中,以便它们可以在多个测试文件中重复使用。我首先想到的是要建立一个fixtures.py
文件如重用pytest夹具
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
。这种情况的建议解决方案是什么?
虽然这可能是一个很好的主意,以避免大量的数据库连接,但这并没有解决我的问题中有关如何将夹具导入测试文件的问题。 –
注意:你需要把它们放在你的测试目录中* conftest.py * pytest会在* conftest.py * – theY4Kman
@ theY4Kman中搜索fixtures请问你会发布这个答案吗? –