Skip to content

Commit f6e1c4d

Browse files
sayakpaulclaude
andauthored
[tests] guard peft imports in test_lora_loader_utils (#14434)
The Hub staging-tests job runs `pytest -m "is_staging_test" tests`, which imports every test module at collection time, but that job doesn't install peft. The top-level `from peft import ...` added in #14385 therefore breaks collection with exit code 2 on every PR. Guard the imports behind `is_peft_available()` (as `tests/lora/utils.py` already does) and mark the one test that needs them with `require_peft_backend`. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent d6726f3 commit f6e1c4d

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

tests/lora/test_lora_loader_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@
1818
import pytest
1919
import torch
2020
import torch.nn as nn
21-
from peft import LoraConfig
22-
from peft.tuners.tuners_utils import BaseTunerLayer
2321
from safetensors.torch import save_file
2422

2523
from diffusers.configuration_utils import ConfigMixin
2624
from diffusers.loaders import StableDiffusionLoraLoaderMixin, lora_base
2725
from diffusers.loaders.lora_base import LoraBaseMixin
2826
from diffusers.loaders.peft import PeftAdapterMixin
2927
from diffusers.models.modeling_utils import ModelMixin
28+
from diffusers.utils.import_utils import is_peft_available
29+
30+
from ..testing_utils import require_peft_backend
31+
32+
33+
if is_peft_available():
34+
from peft import LoraConfig
35+
from peft.tuners.tuners_utils import BaseTunerLayer
3036

3137

3238
LORA_KEY = "unet.test.lora_A.weight"
@@ -109,6 +115,7 @@ def test_local_directory_with_multiple_files_warns_and_uses_first(tmp_path, monk
109115
assert "contains more than one weights file" in caplog.text
110116

111117

118+
@require_peft_backend
112119
def test_unfuse_lora_partial_components_keeps_merged_adapters_in_sync():
113120
"""Regression test for gh-14214.
114121

0 commit comments

Comments
 (0)