zoukankan      html  css  js  c++  java
  • Pytest系列(8)

    转自:https://www.cnblogs.com/poloyy/

    一、前言

    • pytest 可以支持自定义标记,自定义标记可以把一个 web 项目划分多个模块,然后指定模块名称执行
    • 譬如我可以标明哪些用例是window下执行的,哪些用例是mac下执行的,在运行代码时候指定mark即可

    二、实际代码

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import pytest
    
    
    @pytest.mark.weibo
    def test_weibo():
        print("测试微博")
    
    
    @pytest.mark.toutiao
    def test_toutiao():
        print("测试头条")
    
    
    @pytest.mark.toutiao
    def test_toutiao1():
        print("再次测试头条")
    
    
    @pytest.mark.xinlang
    class TestClass:
        def test_method(self):
            print("测试新浪")
    
    
    def testnoMark():
        print("没有标记测试")
    
    

    2.1 cmd敲运行命令

    pytest -s -m weibo 08_mark.py
    

    2.2 执行结果

    img

    2.3 如何避免 warnings

    • 创建一个pytest.ini文件(后续详解)
    • 加上自定义mark,如下图
    • 注意:pytest.ini需要和运行的测试用例同一个目录,或在根目录下作用于全局
    [pytest]
    markers =
        weibo: this is weibo page
        toutiao: this is toutiao page
        xinlang: this is xinlang page
    

    ​ 或者

    def pytest_configure(config):
        marker_list = ["weibo","toutiao","xinlang"]
        for markers in marker_list:
            config.addinivalue_line("markers",markers)
    

    2.4 如果不想标记 weibo 的用例,not

    pytest -s -m "not weibo" 08_mark.py
    

    2.5 如果想执行多个自定义标记的用例,or

    pytest -s -m "toutiao or weibo" 08_mark.py
    
  • 相关阅读:
    最小生成数kruskal算法和prim算法
    图的表示及遍历
    mysql忘记root用户密码重置密码的方式
    dwr2.0版本的demo
    web.xml中不同版本的servlet头以及版本控制
    初学jboss
    Filter学习总结,顺便提及点servlet3.0异步filter和异步监听
    监听器
    问题发现和解决
    linux学习
  • 原文地址:https://www.cnblogs.com/dongye95/p/14012058.html
Copyright © 2011-2022 走看看