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

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

  •  
  •   niegehedao · 2020-07-05 18:55:17 +08:00 · 1530 次点击
    这是一个创建于 1362 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    4 条回复    2020-07-06 20:42:36 +08:00
    jenlors
        1
    jenlors  
       2020-07-05 21:36:55 +08:00
    fixture 作为 test case 参数,就是其返回值
    linvaux
        2
    linvaux  
       2020-07-05 22:36:53 +08:00
    fixture 化,但是,这玩意儿本身就是一条用例,为毛要搞成数据依赖的用例呢
    niegehedao
        3
    niegehedao  
    OP
       2020-07-05 22:46:11 +08:00
    @linvaux 感觉这样比较方便,我创建一个订单是一条 case,后面的很多 case 依赖这条 case 产生的订单号进行测试,不然每个 case 都要产生一条订单不很麻烦吗,我是小白,刚入职的,不知道理解有没有问题。。。
    linvaux
        4
    linvaux  
       2020-07-06 20:42:36 +08:00
    @niegehedao 那就把常用的上游接口直接封装到 fixture 里面吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3260 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:13 · PVG 20:13 · LAX 05:13 · JFK 08:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.