pytest
pytest copied to clipboard
Fixture executed even if all tests are skipped
I just now updated an old application from pytest 7 to 8 and the following started failing:
# Using pytest 8.4.2
from unittest import TestCase, skipIf
import pytest
@skipIf(True, "reason")
class Foo(TestCase):
@pytest.fixture(autouse=True)
def something(self):
assert 0
def test_bar(self):
pass
- Expected: The assert not being hit since all tests are skipped
- Actual: The assert is hit despite no tests being run.
I found that using pytest.mark.skipif instead of the unittest skipIf works around the issue. The context is that this is a Linux only test and skipped anywhere else, and the fixture also only works on Linux