问题
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