1

I have a fixture that yields my git branch, and I want to skip tests if branch is "master", for example.

I currently do it like this:

import pytest

@pytest.fixture
def branch():
    yield _get_branch()

def test_something(branch):
    if branch == "master":
        pytest.skip("No tests on master")
    
    # test ...

What I want to do is:

import pytest

@pytest.fixture
def branch():
    yield _get_branch()

@pytest.mark.skipif(pytest.GET_FIXTURE_VALUE("branch") == "master", reason="No tests on master")
def test_something(branch):  
    # test ...

but I can't find anyway to pytest.GET_FIXTURE_VALUE.

I found stuff in documentation that mention pytest.config but that seems to be deprecated...

Using python3.6, pytest>=6

I eventually used this answer as a workaround, but I don't want to close this question, because I'm still looking for a better match to my situation

CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
  • 1
    Does this answer your question? [How to skip a pytest using an external fixture?](https://stackoverflow.com/questions/28179026/how-to-skip-a-pytest-using-an-external-fixture) – Szabolcs Mar 14 '22 at 10:26
  • @Szabolcs Saw this while checking for solutions, but this seems not very straight-forward... If this is the only viable solution, I'll just stay with my current implementation – CIsForCookies Mar 14 '22 at 10:28
  • 1
    You can also pass the result of the `_get_branch()` function as a condition to skipif? But I also don't know how does that function behave and what is the underlying logic. – Szabolcs Mar 14 '22 at 10:39
  • Thought of it, but it is technically private, so I would refrain from that – CIsForCookies Mar 14 '22 at 10:40
  • 1
    Then I honestly think an autouse fixture that leverages your `branch` fixture is the way to go, like described in the above link. Or if you'd like to be explicit without repeating youserlf you can create a secondary `skippable_branch` fixture that receives the `branch` fixture as a parameter and does the comparison and skips if needed. – Szabolcs Mar 14 '22 at 10:46

0 Answers0