diff --git a/tests/components/tradfri/test_light.py b/tests/components/tradfri/test_light.py index 8e51e37576e..b8b21db64b7 100644 --- a/tests/components/tradfri/test_light.py +++ b/tests/components/tradfri/test_light.py @@ -72,7 +72,7 @@ TRANSITION_CASES_FOR_TESTS = [None, 0, 1] @pytest.fixture(autouse=True, scope="module") -def setup(request): +def setup(): """Set up patches for pytradfri methods.""" p_1 = patch( "pytradfri.device.LightControl.raw", @@ -83,12 +83,10 @@ def setup(request): p_1.start() p_2.start() - def teardown(): - """Remove patches for pytradfri methods.""" - p_1.stop() - p_2.stop() + yield - request.addfinalizer(teardown) + p_1.stop() + p_2.stop() async def generate_psk(self, code): diff --git a/tests/ruff.toml b/tests/ruff.toml index 18a3ca5626f..e7d0818e8dc 100644 --- a/tests/ruff.toml +++ b/tests/ruff.toml @@ -5,5 +5,6 @@ extend-select = [ "PT001", # Use @pytest.fixture without parentheses "PT013", # Found incorrect pytest import, use simple import pytest instead "PT015", # Assertion always fails, replace with pytest.fail() + "PT021", # use yield instead of request.addfinalizer "PT022", # No teardown in fixture, replace useless yield with return ] \ No newline at end of file