zoukankan      html  css  js  c++  java
  • pytest封神之路第〇步 快速入门

    pytest封神之路第零步 快速入门

    pytest封神之路第一步 tep介绍

    pytest封神之路第二步 132个命令行参数用法

    pytest封神之路第三步 精通fixture

    pytest封神之路第四步 内置和自定义marker

    pytest封神之路第五步 参数化进阶

    pytest封神之路第六步 断言技巧

    pytest封神之路第七步 用例查找原理

    持续更新中...


    背景:本文是在系列第五篇发表后的补充篇章,第一篇介绍了tep,可能对不熟悉pytest的朋友不够友好,特意补充入门篇,帮大家快速了解如何动手写pytest。如果你是从这篇文章第一次阅读,那么请忽略以上。

    安装Python和编辑器PyCharm。Python安装包下载地址是https://www.python.org/downloads/,推荐3.8版本。PyCharm安装包下载地址是

    https://www.jetbrains.com/pycharm/download/ ,下载Community社区版即可。下载后按常规软件安装。

    pytest

    pytest是Python内置包,无需单独安装,但是需要设置

    创建1个Project和1个test.py来试试,左上角点击 File | New Project | create,创建项目。在项目中右键选择 New | File 创建test.py

    接着设置PyCharm,默认PyCharm自带的测试框架是Unittests,在 File | Settings | Tools | Python Integrated Tools | Testing | Default test runner,修改为pytest

    在test.py文件中添加代码

    def test():
        pass
    
    

    这个时候def的左边会出现一个绿色的箭头,点击之后就可以使用pytest运行,注意一定要是 pytest for... 才可以,如果只是 Run test.py,是不走pytest执行的(右上角Edit Configurations删掉来解决)

    执行之后控制台输出信息就可以了

    Testing started at 11:10 AM ...
    "D:\Program Files (x86)\Python38-32\python.exe" "D:\Program Files\JetBrains\PyCharm Community Edition 2020.1.2\plugins\python-ce\helpers\pycharm\_jb_pytest_runner.py" --target test.py::test
    Launching pytest with arguments test.py::test in D:\PycharmProjects\untitled
    
    ============================= test session starts =============================
    platform win32 -- Python 3.8.3, pytest-5.4.3, py-1.9.0, pluggy-0.13.1 -- D:\Program Files (x86)\Python38-32\python.exe
    cachedir: .pytest_cache
    rootdir: D:\PycharmProjects\untitled
    collecting ... collected 1 item
    
    test.py::test PASSED                                                     [100%]
    
    ============================== 1 passed in 0.14s ==============================
    
    Process finished with exit code 0
    
    

    至此,pytest的环境就准备好了。

    tep

    安装tep,在PyCharm中打开左下角的Terminal,既可以用pypi,也可以用国内镜像,推荐国内镜像更快

    pypi

    pip install tep
    

    国内镜像,同时设定超时,提高安装成功率

    pip --default-timeout=600 install -i https://pypi.tuna.tsinghua.edu.cn/simple tep
    

    安装tep的同时,会自动安装requests、allure、faker、jmespath、loguru、deepdiff、pymysql、sqlalchemy、texttable、pandas、numpy等实用第三方包。

    至此,tep的环境就准备好了。

    如果有任何问题,请及时留言联系我。


    所有文章公众号【测试开发刚哥】首发!

    版权申明:本文为博主原创文章,转载请保留原文链接及作者。
  • 相关阅读:
    函数的声明
    数组遍历的方法
    运算符
    变量命名规则
    js条件判断
    vuex使用
    高盛伦敦分部面试
    野村证券伦敦分部面试
    Linux Performance Monitoring Commands
    Linux server上too many open files问题
  • 原文地址:https://www.cnblogs.com/df888/p/13733877.html
Copyright © 2011-2022 走看看