2

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?

Timmy
  • 12,468
  • 20
  • 77
  • 107
  • 1
    The 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 Answers2

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'

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

ntki
  • 2,149
  • 1
  • 16
  • 19