How to run only unmarked tests in pytest

和自甴很熟 提交于 2019-12-04 05:28:45

You can use following code snippet in top level conftest.py.

def pytest_runtest_setup(item):
    envmarker = item.get_marker()
    if envmarker:
        pytest.skip("Skipping as the test has a marker")

Remember that parametrize is also a marker. If you are using parametrization, you can check for that in envmarker and skip conditionally.

The pytest-unmarked plugin is intended to accomplish this.

PyPi's link to the project's home is broken. This is the proper link https://github.com/alyssabarela/pytest-unmarked

More info on using plugins at https://docs.pytest.org/en/latest/plugins.html

Adding the following to your conftest will solve this for you by adding a specific mark to all unmarked test so you can then run something like pytest -m unmarked

def pytest_collection_modifyitems(items, config):
    for item in items:
        if not any(item.iter_markers()):
            item.add_marker("unmarked")

This has the advantage over the how pytest-unmarked does it in that you can still specify other markers e.g. pytest -m 'webtest or unmarked'. Also pytest-unmarked doesn't look maintained and emits warnings.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!