zoukankan      html  css  js  c++  java
  • pytest框架(一)

    代码示例一

    1 # coding=utf-8
    2 
    3 def func(x):
    4     return x + 1
    5 
    6 
    7 def test_answer():
    8     assert func(3) == 5

    运行结果

    E:pyYouYoupytest_demo>pytest test_sample.py
    ============================= test session starts =============================
    platform win32 -- Python 3.6.1, pytest-3.7.2, py-1.5.4, pluggy-0.7.1
    rootdir: E:pyYouYoupytest_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:7: AssertionError

    示例代码二

     1 # coding=utf-8
     2 
     3 class TestClass:
     4     def test_one(self):
     5         x = "this"
     6         assert 'h' in x
     7 
     8     def test_two(self):
     9         x = "hello"
    10         assert hasattr(x, 'check')

    运行结果

    E:pyYouYoupytest_demo>py.test -q test_class.py
    .F                                                                       [100%]
    ================================== FAILURES ===================================
    _____________________________ TestClass.test_two ______________________________
    
    self = <pyYouYou.pytest_demo.test_class.TestClass object at 0x0000000002C319E8>
    
        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.10 seconds
  • 相关阅读:
    CCF NOI1121 逆波兰表达式
    Vijos P1217 乒乓球【模拟+输入输出】
    Vijos P1304 回文数【回文+进制】
    NUC1041 数字三角形【DP】
    CCF NOI1070 汉诺塔游戏
    CCF NOI1069 分解因数
    CCF NOI1149 N皇后问题
    CCF NOI1153 素数环
    CCF NOI1170 质因数分解
    POJ NOI MATH-7832 最接近的分数
  • 原文地址:https://www.cnblogs.com/loveapple/p/9507629.html
Copyright © 2011-2022 走看看