Skip to content

Fixture executed even if all tests are skipped #13885

@lazka

Description

@lazka

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    plugin: unittestrelated to the unittest integration builtin plugintype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions