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
Deteriorator
V2EX  ›  Python

pytest 可以为每个 case 自定义 setup 和 teardown 么?

  •  
  •   Deteriorator · 2021-01-06 16:32:55 +08:00 · 1411 次点击
    这是一个创建于 1178 天前的主题,其中的信息可能已经有所发展或是发生改变。
    每个测试用例的前置条件不同,恢复原始状态的过程也不相同,因此有了这个需求

    哪位大佬指点一下迷津,谢谢~
    3 条回复    2021-01-06 17:09:48 +08:00
    weyou
        1
    weyou  
       2021-01-06 16:48:17 +08:00
    pytest.fixture 了解下
    frostming
        2
    frostming  
       2021-01-06 17:05:08 +08:00
    假设你有 N 个 case,如果 setup teardown 各不相同,工作量只能是 N 不能更少,直接把 setup teardown 写进 case 就是了

    假设有 M 种不同的 setup teardown(M < N), 则写 M 个 fixture,工作量是 M
    最优情况全都一样,那 M=1
    Deteriorator
        3
    Deteriorator  
    OP
       2021-01-06 17:09:48 +08:00
    @weyou 我研究一下
    @frostming 有些 setup 和 teardown 可以复用,之前是写到 case 里面,现在优化一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2777 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 12:07 · PVG 20:07 · LAX 05:07 · JFK 08:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.