PytestUnknownMarkWarning:未知的pytest.mark.xxx-这是错字吗?

问题描述 投票:0回答:1

我有一个名为test.py的文件,其中包含以下代码:

import pytest

@pytest.mark.webtest
def test_http_request():
    pass

class TestClass:
    def test_method(self):
        pass

pytest -s test.py通过,但给出了以下警告:

pytest -s test.py
=============================== test session starts ============================
platform linux -- Python 3.7.3, pytest-5.2.4, py-1.8.0, pluggy-0.13.1
rootdir: /home/user
collected 2 items

test.py ..

=============================== warnings summary ===============================
anaconda3/lib/python3.7/site-packages/_pytest/mark/structures.py:325
  ~/anaconda3/lib/python3.7/site-packages/_pytest/mark/structures.py:325:
    PytestUnknownMarkWarning: Unknown pytest.mark.webtest - is this a typo?  You can register
    custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    PytestUnknownMarkWarning,

-- Docs: https://docs.pytest.org/en/latest/warnings.html
=============================== 2 passed, 1 warnings in 0.03s ===================

环境:Python 3.7.3,pytest 5.2.4,anaconda3

摆脱警告消息的最佳方法是什么?

python-3.x pytest anaconda3 pytest-markers
1个回答
0
投票

要正确处理此问题,您需要register the custom marker。创建一个register the custom marker文件,并将以下内容放入其中。

pytest.ini
© www.soinside.com 2019 - 2024. All rights reserved.