V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ctrlmymood
V2EX  ›  Python

pytest 自定义 def pytest_configure(config)函数报错 INTERNALERROR> AttributeError: 'Config' object has no attribute '_metadata'

  •  
  •   ctrlmymood · 57 天前 · 574 次点击
    这是一个创建于 57 天前的主题,其中的信息可能已经有所发展或是发生改变。
    def pytest_configure(config):
    	config._metadata['测试项目'] = "自动化用例"
        config._metadata['测试地址'] = get__host()
    

    执行 python -m pytest 直接报错:
    函数报错 INTERNALERROR> AttributeError: 'Config' object has no attribute '_metadata'

    大佬看看如何解决,google 了有网友同样的问题,但是没有解决办法

    3 条回复    2024-03-06 17:55:23 +08:00
    walkeronway
        1
    walkeronway  
       57 天前
    参考 https://github.com/pytest-dev/pytest-html/issues/506

    pytest-metadata 降级到 2.0.4

    python -m pytest pip install pytest-metadata==2.0.4
    julyclyde
        2
    julyclyde  
       55 天前
    你这个 Config object 大概并不是你想要的那个类型
    也就是在前一步从配置文件加载,生成 Config 对象的时候大概就已经失败了?

    你在这个函数里,先输出一下 type(config)
    然后再往后执行
    ctrlmymood
        3
    ctrlmymood  
    OP
       52 天前
    @walkeronway 非常感谢,使用你说的方式再执行可以了!👍
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   956 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:32 · PVG 03:32 · LAX 12:32 · JFK 15:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.