一、示例代码一

D:YOYO\
__init__.py test_class.py
# content of test_class.py
class TestClass:
def test_one(self):
x = "this"
assert 'h' in x def test_two(self):
x = "hello"
assert hasattr(x, 'check') def test_three(self):
a = "hello"
b = "hello world"
assert a in b test_sample.py
# content of test_sample.py
def func(x):
return x +1 def test_answer():
assert func(3)==5

二、代码示例二

E:\pyYouYou\pytest_demo>pytest -k "test_ and not two"
============================= test session starts =============================
platform win32 -- Python 3.6.1, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
rootdir: E:\pyYouYou\pytest_demo, inifile:
collected 4 items / 1 deselected test_class.py .. [ 66%]
test_sample.py F [100%] ================================== FAILURES ===================================
_________________________________ test_answer _________________________________ def test_answer():
> assert func(3) == 5
E assert 4 == 5
E + where 4 = func(3) test_sample.py:8: AssertionError
============== 1 failed, 2 passed, 1 deselected in 0.13 seconds ===============

三、代码示例三

E:\pyYouYou\pytest_demo>pytest test_sample.py::test_answer
============================= test session starts =============================
platform win32 -- Python 3.6.1, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
rootdir: E:\pyYouYou\pytest_demo, inifile:
collected 1 item test_sample.py F [100%] ================================== FAILURES ===================================
_________________________________ test_answer _________________________________ def test_answer():
> assert func(3) == 5
E assert 4 == 5
E + where 4 = func(3) test_sample.py:8: AssertionError
========================== 1 failed in 0.05 seconds ===========================
E:\pyYouYou\pytest_demo>pytest test_class.py::TestClass::test_three
============================= test session starts =============================
platform win32 -- Python 3.6.1, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
rootdir: E:\pyYouYou\pytest_demo, inifile:
collected 1 item test_class.py . [100%] ========================== 1 passed in 0.03 seconds ===========================

四、代码示例四

E:\pyYouYou\pytest_demo>pytest -x test_class.py
============================= test session starts =============================
platform win32 -- Python 3.6.1, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
rootdir: E:\pyYouYou\pytest_demo, inifile:
collected 3 items test_class.py .F ================================== FAILURES ===================================
_____________________________ TestClass.test_two ______________________________ self = <pyYouYou.pytest_demo.test_class.TestClass object at 0x000000000389E7F0> def test_two(self):
x = "hello"
> assert hasattr(x, 'check')
E AssertionError: assert False
E + where False = hasattr('hello', 'check') test_class.py:10: AssertionError
===================== 1 failed, 1 passed in 0.06 seconds ======================

五、代码示例五

E:\pyYouYou\pytest_demo>pytest --maxfail=2
============================= test session starts =============================
platform win32 -- Python 3.6.1, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
rootdir: E:\pyYouYou\pytest_demo, inifile:
collected 4 items test_class.py .F. [ 75%]
test_sample.py F [100%] ================================== FAILURES ===================================
_____________________________ TestClass.test_two ______________________________ self = <pyYouYou.pytest_demo.test_class.TestClass object at 0x00000000038AE780> def test_two(self):
x = "hello"
> assert hasattr(x, 'check')
E AssertionError: assert False
E + where False = hasattr('hello', 'check') test_class.py:10: AssertionError
_________________________________ test_answer _________________________________ def test_answer():
> assert func(3) == 5
E assert 4 == 5
E + where 4 = func(3) test_sample.py:8: AssertionError
===================== 2 failed, 2 passed in 0.09 seconds ======================

pytest框架(二)的更多相关文章

  1. pycharm中脚本执行的3种模式(unittest框架、pytest框架、普通模式)

    背景知识,某次使用HTMLTestRunner的时候,发现一直都无法导出报告,后来查询资料发现了一些坑,现在整理一下来龙去脉. 一:pycharm默认的是pytest框架去执行unittest框架的测 ...

  2. pytest框架之rerunfailures失败重运行机制

    web自动化测试中,稳定性在整个测试运行中都至关重要,但不能保证测试脚本或者测试环境一直都能够稳定,它牵扯到诸多因素,在这里就不赘述,pytest框架相较于unittest的一大优势就在于拥有用例失败 ...

  3. 【Pytest01】全网最全最新的Pytest框架快速入门

    一.Pytest简介pytest是一个非常成熟的全功能的Python测试框架,主要有一下几个特点:1.简单灵活,容易上手,支持参数化2.能够支持简单的单元测试和复杂的功能测试,还可以用来做seleni ...

  4. pytest框架使用教程

    Pytest框架 一.简介 pytest:基于unittest之上的单元测试框架 有什么特点? 自动发现测试模块和测试方法 断言更加方便,assert + 表达式,例如 assert 1 == 1 灵 ...

  5. pytest框架的安装与使用

    pytest框架的安装与使用 一,pytest了解 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高. ...

  6. 『德不孤』Pytest框架 — 1、Pytest测试框架介绍

    目录 1.什么是单元测试框架 2.单元测试框架主要做什么 3.单元测试框架和自动化测试框架有什么关系 4.Pytest测试框架说明 5.Pytest框架和Unittest框架区别 (1)Unittes ...

  7. Jersey框架二:Jersey对JSON的支持

    Jersey系列文章: Jersey框架一:Jersey RESTful WebService框架简介 Jersey框架二:Jersey对JSON的支持 Jersey框架三:Jersey对HTTPS的 ...

  8. pytest框架之fixture详细使用

    本人之前写了一套基于unnitest框架的UI自动化框架,但是发现了pytest框架之后觉得unnitest太low,现在重头开始学pytest框架,一边学习一边记录,和大家分享,话不多说,那就先从p ...

  9. Appium 并发多进程基于 Pytest框架

    前言: 之前通过重写unittest的初始化方法加入设备参数进行并发,实现了基于unittest的appium多设备并发,但是考虑到unittest的框架实在过于简陋,也不方便后期的Jenkins的持 ...

  10. pytest 框架自动化Selenium 之yield 使用

    环境 python 3.7 由于3.0-3.5以下部分pytest可能有部分兼容问题安装建议2.7-2.9,3.5-最新 pip install pytest专属 pytest框架包 pip inst ...

随机推荐

  1. python获取当前的时间

    打印出当前的年月日时分秒 print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) 2018-09-05 09:39: ...

  2. jQuery/CSS3实现Android Dock效果

    在线演示 本地下载

  3. Dual Path Networks(DPN)——一种结合了ResNet和DenseNet优势的新型卷积网络结构。深度残差网络通过残差旁支通路再利用特征,但残差通道不善于探索新特征。密集连接网络通过密集连接通路探索新特征,但有高冗余度。

    如何评价Dual Path Networks(DPN)? 论文链接:https://arxiv.org/pdf/1707.01629v1.pdf在ImagNet-1k数据集上,浅DPN超过了最好的Re ...

  4. win7 jenkins 修改主目录

    1.安装tomcat 2.下载Jenkins.war包,把Jenkins.war放在D:\01Install\tomcat\webapps目录下,启动tomcat

  5. MCI支持的格式在注册表中的位置

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

  6. MySQL上周新增激活用户在上周下单情况_20161107周一

    上周新增激活用户在上周下单情况 1.上周激活用户明细 #上周激活用户明细 SELECT a.城市,a.用户ID,a.用户名称,b.用户地址,b.联系电话,a.订单日期,c.年周,c.上周一,a.订单I ...

  7. python+selenium自动化测试环境搭建

    selenium 是一个web的自动化测试工具,不少学习功能自动化的同学开始首选selenium ,相因为它相比QTP有诸多有点: *  免费,也不用再为破解QTP而大伤脑筋 *  小巧,对于不同的语 ...

  8. WPF DatePicker 的textbox的焦点

    要得到DatePicker的textchange属性, 必须通过TextBoxBase.TextChanged 事件来处理. 想要判断是否当前DatePicker的textbox获取到焦点, 可以通过 ...

  9. 【VS工程设置】 编译动态库,命令行添加参数,不使用预编译头,指定该项目链接 哪种 运行库

    编译动态库 注意: 动态库: [目标文件扩展] => .dll + [配置类型] => 动态库(.dll) 静态库: [目标文件扩展] => .lib + [ 配置类型]=> ...

  10. 用expressjs写RESTful API

    http://blog.csdn.net/kiwi_coder/article/details/36424671     用expressjs写RESTful API http://blog.csdn ...