首页 > 其他分享 >pytest

pytest

时间:2023-04-24 22:13:41浏览次数:28  
标签:py Terminal pip pytest install test

Pycharm 内装 pytest,

Terminal内输入

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytest
#原命令pip install pytest,因为网速不好此处用清华网址的镜像

Pytest文件命名规范

  1. .py测试文件必须以 test_ 开头(或 _test 结尾)
  2. 测试方法必须以 test_ 开头
  3. 测试类必须以 Test_ 开头,并且不能有 init 方法

以 pytest 文件命名规范写完一个测试脚本如 test_one.py 想运行时,需要

  Terminal内输入:pytest test_one.py

  注:此时不能用pycharm自带的绿色小三角按钮运行,因为此时默认为unitest运行方式

    若想将默认更改为pytest则如下图

               

 

 

 

标签:py,Terminal,pip,pytest,install,test
From: https://www.cnblogs.com/w-c-y/p/17351108.html

相关文章

  • 自动化测试框架pytest教程
    快速入门准备安装推荐安装anaconda,默认带pytest#pip3installpytest...$pytest-h#查看帮助...参考资料:https://pytest.orghttps://pypi.org/project/pytest第一个实例(通过)deftest_passing():assert(1,2,3)==(1,2,3)函数test_passing()......
  • uiautomator2+app ui自动化用例报错截图pytest_runtest_makereport
    pytest提供了pytest_runtest_makereport这个方法,可以捕获用例的执行情况。根据官方提供的示例,在conftest.py文件中添加如下代码就可以捕获每个用例的执行结果。那么pytest_runtest_makereport作用:对于给定的测试用例(item)和调用步骤(call),返回一个测试报告对象(_pytest.runne......
  • 02-pytest运行报错
    #运行时提示:pytest-Windowsfatalexception:code0x8001010d#解决方法:pytest.ini中加上no:faulthandleraddopts=-vs-pno:faulthandler--html../report/re.html#运行时警告:     DeprecationWarning:invalidescapesequence\d#解决方......
  • python+playwright 学习-49 pytest-xdist 多进程执行用例
    前言在实际工作中项目下的web自动化用例非常多,单进程执行会消耗很长的运行时间,可能运行一次用例得几个小时。为了加快用例的运行速度,可以使用pytest-xdist多进程执行用例。但并不是说你写的用例,直接安装插件就能使用,实际使用的过程中还会遇到很多的问题。pytest-xdist多进程执行......
  • pytest结合allure-pytest插件 生成allure测试报告
     注意:allure-pytest 从1.7之后已弃用,从2.0版本开始迁移至 allure-python 项目(即使用allure2),另外要运行allure命令行也需要Java的支持。1、安装allure-pytestpipinstall-U allure-pytest 这将安装allure-pytest和allure-python-commons程序包,以生成与allure2兼容的报告......
  • pytest + yaml 框架 -25.参数化数据支持读取外部文件txt/csv/json/yaml
    前言v1.2.2版本开始,参数化数据支持读取外部文件,文件格式可以支持:txt/csv/json/yaml参数化的实现用例参数化的实现,我设计了2种实现方式参数化方式1:config:name:post示例fixtures:username,passwordparameters:-[test1,'123456']-[t......
  • pytest 的前置与后置处理详谈
    pytest的前置与后置处理Pytest贴心的提供了类似setup、teardown的方法,并且还超过四个,一共有十种模块级别:setup_module、teardown_module函数级别:setup_function、teardown_function,不在类中的方法类级别:setup_class、teardown_class方法级别:setup_method、teardown_method......
  • pytest+selenium+allure
     您可以使用pip安装SeleniumWebDriver:```pipinstallselenium```3.安装pytest您可以使用pip安装pytest:```pipinstallpytest```4.安装pytest-xdistpytest-xdist是一个pytest插件,用于并行运行测试。您可以使用以下命令安装:```pipinstallpytest-xdist......
  • Python+Requests+Pytest接口自动化测试微信接口实例
         pytest.ini配置文件[pytest]log_cli=truelog_level=NOTSETlog_format=%(asctime)s%(levelname)s%(message)slog_date_format=%Y-%m-%d%H:%M:%Saddopts=-vs--alluredir./temp-m'file'log_file=./log/test.loglog_file_level=infol......
  • pytest + yaml 框架 -24.单个用例中参数化功能实现
    前言早期版本参数化功能实现只支持在config中全局的地方写parameters关键字,只实现了基本的功能。v1.2.1版本对parameters参数化功能做了进一步的细分,支持在case用例中针对单个用例的参数化了。parameters参数化用例参数化的实现,我设计了2种实现方式参数化方式1:con......