pytest_series(mark) - use custom marker mark

foreword

  • pytest can support custom tags, which can divide a web or app project into multiple modules, and then specify the module name to execute
  • For example, I can indicate which use cases are executed under window and which use cases are executed under mac, just specify the mark when running the code
  • For example, I can indicate which use cases are executed under iOS and which use cases are executed under android, just specify the mark when running the code

Above code [web example]

 

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("没有标记测试")

cmd [terminal] knock to run the command

pytest -s -m weibo 08_mark.py

Results of the

How to avoid warnings

  • Create a pytest.ini file (detailed later)
  • Add a custom mark, as shown below
  • Note: pytest.ini needs to be in the same directory as the test case to be run, or act globally in the root directory

If you don't want to mark the use case of weibo, we can directly negate it

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

If you want to do multiple custom tag use cases


pytest -s -m "toutiao or weibo" 08_mark.py

 

Guess you like

Origin blog.csdn.net/qq_41663420/article/details/129805667