How to skip a pytest using an external fixture?

前端 未结 4 458
悲哀的现实
悲哀的现实 2020-12-09 15:46

Background

I am running a py.test with a fixture in a conftest file. You can see the code below(this all works fine):

example_test.py

4条回答
  •  执念已碎
    2020-12-09 16:34

    Using inspiration from this answer to another SO question, I am using this approach to this problem which works well:

    import pytest
    
    @pytest.fixture(scope='session')
    def requires_something(request):
        something = 'a_thing'
        if request.param != something:
            pytest.skip(f"Test requires {request.param} but environment has {something}")
    
    
    @pytest.mark.parametrize('requires_something',('something_else',), indirect=True)
    def test_indirect(requires_something):
        print("Executing test: test_indirect")
    
    

提交回复
热议问题