如何修复此 AttributeError:“SubRequest”对象没有属性“getfuncargvalue”?

Posted

技术标签:

【中文标题】如何修复此 AttributeError:“SubRequest”对象没有属性“getfuncargvalue”?【英文标题】:How do I fix this AttributeError: 'SubRequest' object has no attribute 'getfuncargvalue'? 【发布时间】:2020-03-11 21:39:21 【问题描述】:

我正在 Mongo 大学参加 MongoDB for Python Developers 课程,但尝试在计算机 mac 上运行 pytest -m 连接时遇到了这个问题:

tests/test_db_connection.py EEEE [100%]

================================================ ============ 错误 ===================================== ======================= _____________________________________________ 设置 test_atlas_setup 时出错 _____________________________________________

请求 = > monkeypatch = <_pytest.monkeypatch.monkeypatch>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

E AttributeError: 'SubRequest' 对象没有属性 'getfuncargvalue'

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytest_flask/plugin.py:109:AttributeError _______________________________________ 设置 test_basic_movies 时出错 _____________________________________________

请求 = > monkeypatch = <_pytest.monkeypatch.monkeypatch>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

E AttributeError: 'SubRequest' 对象没有属性 'getfuncargvalue'

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytest_flask/plugin.py:109:AttributeError _________________________________________ 设置 test_search_by_movie_id 时出错 ___________________________________________

请求 = > monkeypatch = <_pytest.monkeypatch.monkeypatch>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

E AttributeError: 'SubRequest' 对象没有属性 'getfuncargvalue'

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytest_flask/plugin.py:109:AttributeError _________________________________________ 设置 test_simple_text_search 时出错 __________________________________________

请求 = > monkeypatch = <_pytest.monkeypatch.monkeypatch>

@pytest.fixture(autouse=True)
def _configure_application(request, monkeypatch):
    """Use `pytest.mark.options` decorator to pass options to your application
    factory::

        @pytest.mark.options(debug=False)
        def test_something(app):
            assert not app.debug, 'the application works not in debug mode!'

    """
    if 'app' not in request.fixturenames:
        return
  app = request.getfuncargvalue('app')

E AttributeError: 'SubRequest' 对象没有属性 'getfuncargvalue'

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pytest_flask/plugin.py:109: AttributeError

【问题讨论】:

【参考方案1】:

根据您的错误消息,您使用的是 Python3.7。

您可能正在使用已弃用的getfuncargvalue 而不是getfixturevalue,如here 所述。

【讨论】:

【参考方案2】:

同样的事情发生在我身上。我将 attrs==19.1.0 添加到 requirements.txt 并且它起作用了!

【讨论】:

很高兴知道:)【参考方案3】:

尝试更新项目的依赖,Pytest、pymongo和Flask的默认依赖都比较老了。更新后我设法让测试通过了。

【讨论】:

更新所有软件包并解决了兼容性问题,但没有奏效

以上是关于如何修复此 AttributeError:“SubRequest”对象没有属性“getfuncargvalue”?的主要内容,如果未能解决你的问题,请参考以下文章

如何修复AttributeError:模块'numpy'没有属性'square'[关闭]

如何修复“AttributeError:模块'tensorflow'没有属性'get_default_graph'”?

如何修复 AttributeError:“系列”对象没有“查找”属性?

如何修复python2.7中的“AttributeError:'module'对象没有属性'storage'”错误

如何修复 AttributeError:“列表”对象没有属性“编码”

如何修复 AttributeError:“Image”对象没有“seek”属性。您是说:“种子”吗?