pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Fixture executed even if all tests are skipped

Open lazka opened this issue 1 month ago • 9 comments

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

lazka avatar Nov 07 '25 14:11 lazka