一、示例代码一

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. 使用valgrind进行内存泄漏和非法内存操作检测

    valgrind是一个强大的工具,最常用的功能是用它来检测内存泄漏和非法内存的使用.要想让valgrind报告的更加细致,请使用-g进行编译. 基本命令如下: $ valgrind --tool=me ...

  2. Contiki 2.7 Makefile 文件(三)

    2.第二部分 这里的usage,targets,savetarget,savedefines都是伪目标. 和all不同,这些伪目标不会被执行,除非显式指定这些目标. 这里有两个目标savetarget ...

  3. Html+CSS3技术实现动画、天气图标动态效果 效果很酷

    1. [代码][CSS]代码    <svg    version="1.1"    id="sun"    class="climacon c ...

  4. Android 7.1 GUI系统-窗口管理WMS-Surface管理(四)

    Surface的管理 Surface是窗口能真正显示到物理屏幕上的基础,由surfaceflinger管理,可以通过WindowStateAnimator.java中的变量mDrawState来查看每 ...

  5. nginx websocket

    前两天折腾了下socketio,部署完发现通过nginx代理之后前端的socket无法和后端通信了,于是暴查一通,最后解决问题: location / { proxy_pass http://127. ...

  6. linux命令学习笔记(62)-curl命令-url下载工具

    linux curl是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载,所以是综合 传输工具,但按传统,习惯称url为下载工具. 一,curl命令参数,有好多我没有用过,也不知道 ...

  7. CSS实现简单无缝滚动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. P2024 [NOI2001]食物链[扩展域并查集]

    大水题一道啊,几分钟切掉. 还是扩展域,每个点拆3个点,之间连边表示有关系(即捕食关系).然后随便判定一下就好了,不难,毕竟NOI上古题目. #include<iostream> #inc ...

  9. 【Lintcode】013.strStr

    题目: For a given source string and a target string, you should output the first index(from 0) of targ ...

  10. poj 2420 A Star not a Tree?——模拟退火

    题目:http://poj.org/problem?id=2420 精度设成1e-17,做三遍.ans设成double,最后再取整. #include<iostream> #include ...