Skipping pytest unless a parameter is present

左心房为你撑大大i 提交于 2019-12-07 20:05:22

问题


I want to use unittest.skiptest but only skip a test if a parameter is given at command line. This lets me do integration tests easier. How can I do this?


回答1:


The documentation is filled with helpful information. You'll find what you are looking for here.

No need to use skiptest at all.

Basically, just use the conftest.py file to define a new command line option and then go about marking the tests with your new annotation. Note: The annotation and parameter can be different..




回答2:


You can use markers for that. You mark the task with a tag, and with the -m command line argument you can write logical expressions (de)selecting the tests for running.

@pytest.mark.slowtest
def test_case1():
    pass

To skip it, run it like this:

py.test -m 'not slowtest'

Docs: https://pytest.org/latest/example/markers.html



来源:https://stackoverflow.com/questions/31507713/skipping-pytest-unless-a-parameter-is-present

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