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?
Asked
Active
Viewed 879 times
2
-
1The title does not fit the question: The title asks how to default skip a test, i.e. without any command line parameter present. This is what I would like to achieve. But it turns out this question is not the same as my question: http://stackoverflow.com/questions/33084190/default-skip-test-unless-command-line-parameter-present-in-py-test – Roland Puntaier Oct 12 '15 at 14:57
2 Answers
2
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..

Ross
- 1,013
- 14
- 32
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'

ntki
- 2,149
- 1
- 16
- 19