【问题标题】:.Pytest session scoped fixture showing error in pylint.Pytest 会话范围的夹具在 pylint 中显示错误
【发布时间】:2020-04-27 02:18:13
【问题描述】:

我创建了一个会话范围的固定装置,以便我的网络驱动程序与所有测试保持一致(浏览器不会在测试之间关闭), 但由于某种原因,我在每个测试中都收到一个错误,即“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')

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

“TestLogin”实例没有“驱动程序”成员 pylint(no-member)

【问题讨论】:

    标签: python selenium visual-studio-code pytest pylint


    【解决方案1】:

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

    【讨论】:

    • 你有推荐的 linter 与可以理解 pytest 固定装置的 vscode 一起使用吗?
    • 很遗憾我没有。
    猜你喜欢
    • 2020-01-16
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 2022-06-12
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多