How to run a particular test on my local machine only, using pytest

Viewed 217

I have a couple of tests which I'd like to run on my local machine, but not on CI.

I'm using pytest, how do I go about this?

I could test to see that there's a particular environment key, and only run the test if it's present, something like:

def test_something():
    if 'key' in os.environ:
        < do test stuff >

I feel as though there's probably a better approach though, perhaps using some pytest method / decorator that I'm unaware of.

1 Answers

You can use the feature skipif of pytest:

skipif

If you wish to skip something conditionally then you can use skipif instead.

import sys


@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test_function():
    ...

So try something like:

@pytest.mark.skipif("key" not in os.environ)
def test_something():
    ...
Related