Timmy
Timmy

Reputation: 12828

Skipping pytest unless a parameter is present

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?

Upvotes: 2

Views: 943

Answers (2)

ntki
ntki

Reputation: 2304

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

Upvotes: 2

Ross
Ross

Reputation: 1033

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..

Upvotes: 2

Related Questions