推荐学习书目
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 · Mar 1, 2024 · 2704 views
    This topic created in 827 days ago, the information mentioned may be changed or developed.
    def pytest_configure(config):
    	config._metadata['测试项目'] = "自动化用例"
        config._metadata['测试地址'] = get__host()
    

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

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

    3 replies    2024-03-06 17:55:23 +08:00
    walkeronway
        1
    walkeronway  
       Mar 1, 2024
    参考 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  
       Mar 3, 2024
    你这个 Config object 大概并不是你想要的那个类型
    也就是在前一步从配置文件加载,生成 Config 对象的时候大概就已经失败了?

    你在这个函数里,先输出一下 type(config)
    然后再往后执行
    ctrlmymood
        3
    ctrlmymood  
    OP
       Mar 6, 2024
    @walkeronway 非常感谢,使用你说的方式再执行可以了!👍
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   861 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:51 · PVG 04:51 · LAX 13:51 · JFK 16:51
    ♥ Do have faith in what you're doing.