pytest用例 - 用例规范

用例规范

  用例设计原则
    1.文件名以test_*.py和*_test.py
    2.以test_开头的函数
    3.以Test开头的类,test_开头的方法,且不能带有__ini__方法
    4.所有的包package必须要有__init__.py文件
0
0
0
import pytest

class TestDemo(object):
    #参数化,每个用例都不会相互影响,即使中间有用例运行失败,后面的用例还是会进行
    @pytest.mark.parametrize("test_input,expected",
                             [("3+5", 8),
                              ("2*4", 8),
                              ("54/6", 8),
                              ("7-1", 6),
                              ])
    def test_eval(self, test_input, expected):
        assert eval(test_input) == expected
  运行方式
    1.右键的选框选中Run ‘pytest for ...’
0
    2.命令行执行‘pytest 路径.文件’
0
    3.命令行执行 ‘python -m pytest 路径/文件’
0
posted @ 2022-05-26 10:48  乌醍  阅读(147)  评论(0)    收藏  举报