当前位置: 首页 > wzjs >正文

邯郸信息港邯郸信息网seo排名优化方法

邯郸信息港邯郸信息网,seo排名优化方法,西宁网站系统建设,注册域名要多久缩写单词含义.passed通过Ffailed失败(用例执行时报错)Eerror出错(fixture执行报错)sskipped跳过Xxpassed预期外的通过(不符合预期)xxfailed预期内的失败(符合预期) 1.pytest 配置 1…
缩写单词含义
.passed通过
Ffailed失败(用例执行时报错)
Eerror出错(fixture执行报错)
sskipped跳过
Xxpassed预期外的通过(不符合预期)
xxfailed预期内的失败(符合预期)


1.pytest 配置

1.查看pytest的所有配置项

在pycharm的terminal中 输入下面的代码,即可查看所有的配置项

pytest -h                                                                                                                                    usage: pytest [options] [file_or_dir] [file_or_dir] [...]

部分配置项 :


-v, --verbose         Increase verbosity   # 增加输出详细程度
-q, --quiet           Decrease verbosity   # 减少输出详细程度-x, --exitfirst       Exit instantly on first error or failed test   # 在第一个错误或测试失败时立即退出markers (linelist):   Register new markers for test functions # 注册新标记
addopts (args):       Extra command line options  # add options:添加额外的命令行选项,在使用ini文件配置时使用 
2.配置:配置有两种方法:
  • 命令行参数
  •  ini配置文件
3.命令行参数

命令行参数就是每次执行测试的时候在 pytest 命令后面添加 参数:下面是一个简单的测试代码:

def test_pass():assert (10 == 10)

在terminal中执行  pytest 输出为 

接下来在terminal中执行 pytest -v 命令,输出为:

        可以看到  pytest -v 命令的输出比 pytest 命令的输出更详细,而且 -v  是可以叠加的,也就是可以使用多个v来尽可能的增加详细程度 ,-vv,-vvv,-vvvv都是可以的。同理,-q 也是一致,并且 -v -q 还可以同时使用,不过一个增加详细程度,一个减少详细程度,同时使用效果就抵消了。多个v 和多个q也可以同时使用,例如:pytest -vvv -qqqq  就看哪个多了。鉴于这里的用例比较简单,在减少/增加详细程度也不会有太大的变化,就不再放图了。

4.ini配置文件

      每次都要在命令后加相应的配置项很麻烦,更加方便的方法是使用ini配置文件,将需要使用的配置项放进去,这样每次在执行的时候,由系统自动的将配置项加到命令后面,就不需要在手动添加了。

  1. 根目录中创建   pytest.ini 文件
  2. 创建 pytest 选择器 [pytest]
  3. 按行添加需要的配置项(addopts)
[pytest]
addopts = -s -v

2.标记mark

mark的主要作用是让用例变得不同,实现用例的筛选。标记有两种,一种是pytest框架内置的标记,一种是用户自定义的标记

1.用户自定义的标记

1.注册:在ini配置文件中实现,例如

markers =apiuiut

2.标记,标记是可以叠加的。

import pytest@pytest.mark.ut   # 标记
def test_pass():assert 1 == 1@pytest.mark.api   标记
def test_fail():assert 1 == 2@pytest.mark.ut   # 标记
@pytest.mark.ui   # 标记
def test_skip():assert 1 == 1

3.筛选

可以根据标记对用例进行筛选,terminal / ini配置文件中均可实现。例如, 只执行拥有api标记的用例

ini 文件配置 

addopts = -s -v -m api

terminal中实现

pytest -m api  # 只执行拥有api标记的用例

D:\python_project\API_Auto\API1\venv\Scripts\python.exe D:\python_project\API_Auto\API1\run.py 
============================= test session starts =============================
platform win32 -- Python 3.10.6, pytest-8.3.5, pluggy-1.5.0 -- D:\python_project\API_Auto\API1\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\python_project\API_Auto\API1
configfile: pytest.ini
collecting ... collected 3 items / 2 deselected / 1 selectedtest_mark.py::test_fail FAILED================================== FAILURES ===================================
__________________________________ test_fail __________________________________@pytest.mark.apidef test_fail():
>       assert 1 == 2
E       assert 1 == 2test_mark.py:11: AssertionError
=========================== short test summary info ===========================
FAILED test_mark.py::test_fail - assert 1 == 2
======================= 1 failed, 2 deselected in 0.09s =======================Process finished with exit code 0

      可以看到,一共有三个用例,但是只执行了拥有api标记的用例,并且这个用例执行结果是失败的。

      另外,标记支持逻辑运算。

pytest -m ("ut or api")    # 执行标记为 ut 或者 api 的用例

D:\python_project\API_Auto\API1\venv\Scripts\python.exe D:\python_project\API_Auto\API1\run.py 
============================= test session starts =============================
platform win32 -- Python 3.10.6, pytest-8.3.5, pluggy-1.5.0 -- D:\python_project\API_Auto\API1\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\python_project\API_Auto\API1
configfile: pytest.ini
collecting ... collected 3 itemstest_mark.py::test_pass PASSED
test_mark.py::test_fail FAILED
test_mark.py::test_skip PASSED================================== FAILURES ===================================
__________________________________ test_fail __________________________________@pytest.mark.apidef test_fail():
>       assert 1 == 2
E       assert 1 == 2test_mark.py:11: AssertionError
=========================== short test summary info ===========================
FAILED test_mark.py::test_fail - assert 1 == 2
========================= 1 failed, 2 passed in 0.11s =========================Process finished with exit code 0

     可以看到,三个用例都符合条件,所以三个用例都被执行了。 

pytest -m ("ut and ui")    # 执行同时具有标记为 ut 和 ui 的用例

D:\python_project\API_Auto\API1\venv\Scripts\python.exe D:\python_project\API_Auto\API1\run.py 
============================= test session starts =============================
platform win32 -- Python 3.10.6, pytest-8.3.5, pluggy-1.5.0 -- D:\python_project\API_Auto\API1\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\python_project\API_Auto\API1
configfile: pytest.ini
collecting ... collected 3 items / 2 deselected / 1 selectedtest_mark.py::test_skip PASSED======================= 1 passed, 2 deselected in 0.01s =======================Process finished with exit code 0

 可以看到,只有一个用例符合要求,所以只执行了这一个用例

@pytest.mark.ut   # 标记
@pytest.mark.ui   # 标记
def test_skip():assert 1 == 1
2.框架内置标记
  1.  不需要注册,直接使用
  2.  不仅用于筛选,还有特殊效果
  3.  不同的标记,拥有不同的效果
    1. skip:无条件跳过
    2. skipif:有条件跳过
    3. xfail:预期失败
    4. parametrize:参数化: 框架为用例传递参数
    5. usefixture:使用fixture
import pytest@pytest.mark.skip  # 跳过
def test_skip():assert 1 + 1 == 2@pytest.mark.skipif(1 == 1, reason="1=1,结果为真,所以skip")  # 跳过
def test_skipif():assert 1 + 1 == 4@pytest.mark.xfail   # 预期结果是失败,实际结是失败。是预期内的失败
def test_xfail():assert 1 + 1 == 3@pytest.mark.xfail   # 预期结果是失败,实际结是成功。是预期外的成功
def test_xpass():assert 1 + 1 == 2@pytest.mark.parametrize(   # 参数化"a, b, c",  # 列出参数[# 准备参数的值[1, 1, 2],[1, 1, 3]]
)
def test_param(a, b,  c):assert (a + b) == c
缩写单词含义
.passed通过
Ffailed失败(用例执行时报错)
Eerror出错(fixture执行报错)
sskipped跳过
Xxpassed预期外的通过(不符合预期)
xxfailed预期内的失败(符合预期)

输出结果 :

D:\python_project\API_Auto\API1\venv\Scripts\python.exe D:\python_project\API_Auto\API1\run.py 
============================= test session starts =============================
platform win32 -- Python 3.10.6, pytest-8.3.5, pluggy-1.5.0 -- D:\python_project\API_Auto\API1\venv\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\python_project\API_Auto\API1
configfile: pytest.ini
collecting ... collected 6 itemstest_mark.py::test_skip SKIPPED (unconditional skip)
test_mark.py::test_skipif SKIPPED (1=1,结果为真,所以skip)
test_mark.py::test_xfail XFAIL
test_mark.py::test_xpass XPASS
test_mark.py::test_param[1-1-2] PASSED
test_mark.py::test_param[1-1-3] FAILED================================== FAILURES ===================================
______________________________ test_param[1-1-3] ______________________________a = 1, b = 1, c = 3@pytest.mark.parametrize(   # 参数化"a, b, c",  # 列出参数[# 准备参数的值[1, 1, 2],[1, 1, 3]])def test_param(a, b,  c):
>       assert (a + b) == c
E       assert (1 + 1) == 3test_mark.py:32: AssertionError
=========================== short test summary info ===========================
FAILED test_mark.py::test_param[1-1-3] - assert (1 + 1) == 3
======== 1 failed, 1 passed, 2 skipped, 1 xfailed, 1 xpassed in 0.10s =========Process finished with exit code 0

http://www.dtcms.com/wzjs/496260.html

相关文章:

  • 站长一般几个网站站长seo推广
  • 手机浏览器网站开发杭州网络推广外包
  • 济宁网站建设价格杭州seo网站推广排名
  • 四川省住房和城乡建设厅官网查询seo推广顾问
  • wordpress弹窗客服seo学习论坛
  • 郑州手机网站制作公司哪家好品牌营销推广公司
  • 做网站主流用什么语言google首页
  • 政务网站建设交流发言现在最好的营销方式
  • 怎么做免费的网站推广排名优化怎么做
  • 交友网站建设策划方案(2)网站服务器搭建与管理
  • 网站维护中页面最近新闻摘抄
  • 哪里有做网站服务商百度教育
  • 建设网站要多久的时间专门开发小程序的公司
  • 项目从立项到结束的流程图seo查询系统源码
  • 网站关键词锚文本指向上海优化外包公司排名
  • 国内免费的建网站平台昆明网络推广方式有哪些
  • wordpress网站打开满湖北短视频seo营销
  • 黄海军事最新消息宁波seo外包推广排名
  • 公司网站免费建设刷赞网站推广免费链接
  • 成品网站源码1688自动跳转厦门网站制作全程服务
  • 个人网站设计源码人民日报最新新闻
  • 手机网站域名哪里注册最佳bt磁力狗
  • 越城区建设评市优网站网络推广怎么做方案
  • 做网站 广告费 步骤怎么让百度搜索靠前
  • 做论坛网站怎么赚钱吗北京营销公司排行榜
  • 仪器仪表行业网站建设seo免费系统
  • 可以做用户画像的网站百度推广登录平台网址
  • 湖北营销型网站建设多少钱seo技术网
  • 查看网站是否收录seo搜索引擎优化视频
  • 金山网站制作seo课程培训学校