我正在使用pytest fixture和yield。但是在尝试获取yield return
的值时会收到AttributeErrorconftest.py
@pytest.fixture()
def driver_setup():
driver = webdriver.Firefox()
yield driver
driver.quit()
basetest.py
@pytest.mark.usefixtures("driver_setup")
class BaseTest:
pass
test_example.py
class TestExample(BaseTest):
def test_example(self):
self.driver.get(url)
pass
输出:AttributeError: 'TestExample' object has no attribute 'driver'
答案 0 :(得分:3)
如果您想在测试中访问driver_setup
,则需要更新driver
fixture,如下所示。
@pytest.fixture()
def driver_setup(request):
driver = webdriver
request.cls.driver = driver
yield
driver.quit()
有关详细信息,请参阅http://computableverse.com/blog/pytest-sharing-class-fixtures。