zoukankan      html  css  js  c++  java
  • pycharm写pytest代码

    1.在pycharm里面写pytest用例,先导入pytest

    import pytest
    
    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
    
    if __name__ == "__main__":
        pytest.main('-q test_class.py')
    

     

    运行结果

    .F.                                                                      [100%]
    ================================== FAILURES ===================================
    _____________________________ TestClass.test_two ______________________________
    
    self = <YOYO.test_class.TestClass object at 0x00000000039F9080>
    
        def test_two(self):
            x = "hello"
    >       assert hasattr(x, 'check')
    E       AssertionError: assert False
    E        +  where False = hasattr('hello', 'check')
    
    test_class.py:11: AssertionError
    ============================== warnings summary ===============================
    <undetermined location>
      passing a string to pytest.main() is deprecated, pass a list of arguments instead.
    
    -- Docs: http://doc.pytest.org/en/latest/warnings.html
    1 failed, 2 passed, 1 warnings in 0.06 seconds

    运行结果“.F. ” 点是代表测试通过,F是Fail的意思,1 warnings是用于pytest.main('-q test_class.py')里面参数需要传list,多个参数放list就不会有警告了

    pytest.main(['-q', 'test_class.py'])

    pycharm设置pytest

    1.新建一个工程后,左上角file->Setting->Tools->Python Integrated Tools->项目名称->Default test runner->选择py.test

     改完之后,再重新建个脚本(注意是先改项目运行方式,再写代码才能出来),接下来右键运行就能出来pytest运行了

    pytest是可以兼容unittest脚本的,之前写的unittest用例也能用pytest框架去运行

  • 相关阅读:
    NOIP模拟 1
    wlan
    IS-IS IGP
    linux 基础 软件的安装 *****
    第五部分 linux 软件安装RPM SRPM与YUM
    第四部分 linux使用者管理
    添加rpmforge源 centos 7
    x86 保护模式 十 分页管理机制
    X86保护模式 八操作系统类指令
    poj2230 Watchcow【欧拉回路】【输出路径】(遍历所有边的两个方向)
  • 原文地址:https://www.cnblogs.com/saryli/p/14647083.html
Copyright © 2011-2022 走看看