如何在py.test中使用夹具?

How to use a fixture in py.test?

我可能遗漏了一些明显的东西,但我没有看到。

我在文件 conftest.py 中定义了夹具:

import pytest

@pytest.fixture
def file_tests():
    return "tests.json"

然后我在与 conftest.py 相同的文件夹中进行如下测试(文件 test1.py):

import pytest
from seleniumbase import BaseCase

class MyTestClass(BaseCase):

    def test_basics(self, file_tests):
        print(file_tests)

但是当我运行

py.test test1.py

我收到一个错误

E       TypeError: test_basics() missing 1 required positional argument: 'file_tests'

我错过了什么明显的东西?

也许它正在“干扰” seleniumbase class?

Fixture 无法与从 BaseCase 继承的测试 类 一起使用,因为它是 unittest.TestCasesubclass of unittest.TestCase and pytest doesn't support fixtures