pytest framework for the implementation of test cases reported PytestUnknownMarkWarning by playing tag: Unknown pytest.mark.login_success - is this a typo solution?

Foreword

Bloggers recently when writing code with pytest framework, by [pytest.mark. To hit the label name tag implementation of test cases, there have been performed with patients after a warning ⚠️, while not affecting the execution of test cases, but also looking at very unhappy, feeling a major mistake. Then the Internet looking for a long finally found a solution for this warning ⚠️ program, or very little, so I decided to record.

As shown error

 Warning means pytest probably do not recognize the mark, resulting in labels do not take effect

solution:

1. Single Label

Add the following code in conftest.py directly copy the past, the tag name into your own on the line

def pytest_configure(config):
config.addinivalue_line(
"markers", "login_success" # login_success 是标签名
)

 

2. Multiple tags

Add the following code in conftest.py directly copy the past, the tag name into your own on the line

def pytest_configure(config):
marker_list = ["testmark1","testmark2","testmark3"]  # 标签名集合
for markers in marker_list:
config.addinivalue_line(
"markers", markers
)

3. Add pytest.int profile

The individual labels and methods are applicable to a plurality of tags

[pytest]
markers = testmark1
testmark2
testmark3

This time many people may have a doubt, this pytest.int how to add, add and where, in fact, is as simple as adding a file in any of your projects, create a new file, the file named pytest.int, later operated as there will be no warning

Guess you like

Origin www.cnblogs.com/TestTan/p/11493177.html