python - .Pytest session 范围固定装置显示 pylint 中的错误

标签 python selenium visual-studio-code pytest pylint

我创建了一个 session 范围的固定装置,以便我的网络驱动程序与所有测试保持一致(浏览器不会在测试之间关闭), 但由于某种原因,我在每个测试中收到一个错误,表明“self”没有指定的成员。

代码本身可以工作,但是所有这些错误都使得很难区分什么是真正的错误,什么不是。

我使用 vscode 和默认的 python linter。

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

所有代码也在 pipelinev 中运行。

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')

所有“self”引用上出现的错误是:

Instance of 'TestLogin' has no 'driver' member pylint(no-member)

最佳答案

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

关于python - .Pytest session 范围固定装置显示 pylint 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59664605/

相关文章:

python - 在 python 中使用 selenium 使用用户名和密码登录

visual-studio-code - VSCode:在项目中打开文件

python - 使用 xpath 单击按钮

python - PyXML Ubuntu 13.1,错误 : Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

带有 Windows 共享文件夹的 Python3

python - Linux Gnome,无法安装 KIVY 所需的 PPA

selenium - 使用 [BeforeTestRun] 钩子(Hook)忽略来自specflow的所有测试

typescript - 如何在 Deno 中提取类型

ssh - 如何为 VS Code SSH 远程配置不同的 shell?

python - 如何使用循环和调用另一个函数在 Python 中将两个多项式相乘?