推荐学习书目
› 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 · Jan 6, 2021 · 2390 views
    This topic created in 2093 days ago, the information mentioned may be changed or developed.
    每个测试用例的前置条件不同,恢复原始状态的过程也不相同,因此有了这个需求

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

    假设有 M 种不同的 setup teardown(M < N), 则写 M 个 fixture,工作量是 M
    最优情况全都一样,那 M=1
    Deteriorator
        3
    Deteriorator  
    OP
       Jan 6, 2021
    @weyou 我研究一下
    @frostming 有些 setup 和 teardown 可以复用,之前是写到 case 里面,现在优化一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2343 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 05:25 · PVG 13:25 · LAX 22:25 · JFK 01:25
    ♥ Do have faith in what you're doing.