Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytest AttributeError在使用带屈服的夹具时_Python_Pytest - Fatal编程技术网

Python pytest AttributeError在使用带屈服的夹具时

Python pytest AttributeError在使用带屈服的夹具时,python,pytest,Python,Pytest,我使用的是pytest夹具,产量很高。但在尝试获取产生返回的值时接收AttributeError conftest.py @pytest.fixture() def driver_setup(): driver = webdriver.Firefox() yield driver driver.quit() basetest.py @pytest.mark.usefixtures("driver_setup") class BaseTest: pass tes

我使用的是pytest夹具,产量很高。但在尝试获取产生返回的值时接收AttributeError

conftest.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'对象没有属性“driver”

如果您想在测试中访问
驱动程序,您需要如下更新
驱动程序设置

@pytest.fixture()
def driver_setup(request):
    driver = webdriver
    request.cls.driver = driver
    yield
    driver.quit()

有关更多详细信息,请参阅。

如果您想在测试中访问
驱动程序,您需要如下更新
驱动程序设置
夹具

@pytest.fixture()
def driver_setup(request):
    driver = webdriver
    request.cls.driver = driver
    yield
    driver.quit()
有关更多详细信息,请参阅