推荐学习书目
› 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
niegehedao
V2EX  ›  Python

求问 pytest 一个测试类里面的测试 case 如何共享数据

  •  
  •   niegehedao · Jul 5, 2020 · 2229 views
    This topic created in 2274 days ago, the information mentioned may be changed or developed.

    比如我有一个测试类,第一个 case 会购买一个商品,产生一个订单号,然后下一个 case 会用到,那么第二个 case 要如何获取这个订单号呢

    4 replies  •  2020-07-06 20:42:36 +08:00
    jenlors
        1
    jenlors  
       Jul 5, 2020
    fixture 作为 test case 参数,就是其返回值
    linvaux
        2
    linvaux  
       Jul 5, 2020
    fixture 化,但是,这玩意儿本身就是一条用例,为毛要搞成数据依赖的用例呢
    niegehedao
        3
    niegehedao  
    OP
       Jul 5, 2020
    @linvaux 感觉这样比较方便,我创建一个订单是一条 case,后面的很多 case 依赖这条 case 产生的订单号进行测试,不然每个 case 都要产生一条订单不很麻烦吗,我是小白,刚入职的,不知道理解有没有问题。。。
    linvaux
        4
    linvaux  
       Jul 6, 2020
    @niegehedao 那就把常用的上游接口直接封装到 fixture 里面吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2572 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:35 · PVG 13:35 · LAX 22:35 · JFK 01:35
    ♥ Do have faith in what you're doing.