pytest分类执行pytest.mark.分类名称

1、@pytest.mark.分类名称

2、执行时 '-m','分类名称'

方法一:

class Testb(object):


    datas = ['zhangsan1','lisi1']
    @pytest.mark.smoke
    @pytest.mark.parametrize('data', datas)
    def test0001(self,data,writeb):
        print("传参:",data)
        return data


    datas = ['zhangsan2','lisi2']
    @pytest.mark.smoke
    @pytest.mark.parametrize('data', datas)
    def test0002(self,data,writeb):
        print("传参:",data)
        return data

    datas = ['zhangsan3','lisi3']
    @pytest.mark.web
    @pytest.mark.parametrize('data', datas)
    def test0003(self,data,writeb):
        print("传参:",data)
        return data

if __name__ == '__main__':
        pytest.main(['-s', r'D:\pythonwork\lianxi\pytestlianxi\teste.py','-m','web'])

  

 方法二:

web = pytest.mark.web  
@web
web = pytest.mark.web

class Testb(object):


    datas = ['zhangsan1','lisi1']
    @pytest.mark.smoke
    @pytest.mark.parametrize('data', datas)
    def test0001(self,data,writeb):
        print("传参:",data)
        return data


    datas = ['zhangsan2','lisi2']
    @pytest.mark.smoke
    @pytest.mark.parametrize('data', datas)
    def test0002(self,data,writeb):
        print("传参:",data)
        return data

    datas = ['zhangsan3','lisi3']
    @web
    @pytest.mark.parametrize('data', datas)
    def test0003(self,data,writeb):
        print("传参:",data)
        return data

if __name__ == '__main__':
        pytest.main(['-s', r'D:\pythonwork\lianxi\pytestlianxi\teste.py','-m','web'])

  

posted @ 2021-10-29 10:15  呆呆蒙蒙  阅读(127)  评论(0编辑  收藏  举报