.Pytest 会话范围的夹具显示 pylint 中的错误



>我创建了一个会话范围的夹具,以便我的 Web 驱动程序与所有测试保持一致(浏览器不会在测试之间关闭(, 但是由于某种原因,我从每个测试中都收到一个错误,即"self"没有指定的成员。

代码本身是有效的,但所有这些错误使得很难理解什么是真正的错误,什么不是。

我正在使用 vscode 和默认的 python linter。

有谁知道如何避免这些错误消息而不会失去 linter 本身的功能?

所有代码也在pipenv中运行。

conftest.py

import pytest
@pytest.fixture(scope="session", autouse=True)
def driver_get(request):
from selenium import webdriver
web_driver = webdriver.Chrome()
session = request.node
for item in session.items:
cls = item.getparent(pytest.Class)
setattr(cls.obj,"driver",web_driver)
yield
web_driver.close()

test_file.py

import pytest
class TestLogin:
def testPageload(self):
wait = WebDriverWait(self.driver, 3)
self.driver.get('https://www.website.com')

所有"自我"引用上出现的错误是:

"TestLogin"的实例没有"驱动程序"成员pylint(无成员(

PyLint 可能不理解 pytest 让你做的所有疯狂的事情,所以避免它的唯一方法是逐行关闭警告,完全禁用特定警告,或者尝试使用不同的 linter,这可能会更好地理解代码流。

最新更新