pytest中fixture异常处理

一、高版本pytest使用fixture时,报异常:

AttributeError: 'str' object has no attribute 'iter_parents':

def _test_fixtures(item):
        fixturemanager = item.session._fixturemanager
        fixturedefs = []
        if hasattr(item, "fixturenames"):
            for name in item.fixturenames:
>               fixturedef = fixturemanager.getfixturedefs(name, item.nodeid)
E               AttributeError: 'str' object has no attribute 'iter_parents'

二、解决办法

2.1 更改源代码:

fixturedef = fixturemanager.getfixturedefs(name, item.nodeid)
修改为:
fixturedef = fixturemanager.getfixturedefs(name, item)

2.2 回退版本,本质是版本不兼容导致:

回退pytest的版本由8.2.0回退到8.0.2

pip install pytest==8.0.2

相关推荐

  1. pytestfixture异常处理

    2024-06-06 06:16:02       33 阅读
  2. pytestfixture机制

    2024-06-06 06:16:02       29 阅读
  3. pytestfixture 固件机制

    2024-06-06 06:16:02       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-06 06:16:02       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-06 06:16:02       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-06 06:16:02       82 阅读
  4. Python语言-面向对象

    2024-06-06 06:16:02       91 阅读

热门阅读

  1. Linux之检索文件内容

    2024-06-06 06:16:02       26 阅读
  2. TalkingData数据统计的力量

    2024-06-06 06:16:02       29 阅读
  3. 【WP|4】WordPress 简码(Shortcode)开发详解

    2024-06-06 06:16:02       34 阅读
  4. 408链表的创建和初始化

    2024-06-06 06:16:02       27 阅读
  5. 跨越障碍:解决复杂网页数据提取的挑战

    2024-06-06 06:16:02       29 阅读
  6. k8s_设置dns

    2024-06-06 06:16:02       31 阅读
  7. PMAT安装及使用(Bioinformatics工具-021)

    2024-06-06 06:16:02       27 阅读
  8. Leetcode-3169. Count Days Without Meetings 题解

    2024-06-06 06:16:02       35 阅读
  9. 函数也能当变量?Python一等函数让你大开眼界!

    2024-06-06 06:16:02       27 阅读