Skip to content

Commit 6350a76

Browse files
authored
[chore] properly deprecate src.diffusers.utils.testing_utils. (#13314)
properly deprecate src.diffusers.utils.testing_utils.
1 parent 9d4c9dc commit 6350a76

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

src/diffusers/utils/testing_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from packaging import version
3030

3131
from .constants import DIFFUSERS_REQUEST_TIMEOUT
32+
from .deprecation_utils import deprecate
3233
from .import_utils import (
3334
BACKENDS_MAPPING,
3435
is_accelerate_available,
@@ -67,9 +68,11 @@
6768
global_rng = random.Random()
6869

6970
logger = get_logger(__name__)
70-
logger.warning(
71-
"diffusers.utils.testing_utils' is deprecated and will be removed in a future version. "
72-
"Determinism and device backend utilities have been moved to `diffusers.utils.torch_utils`. "
71+
deprecate(
72+
"diffusers.utils.testing_utils",
73+
"1.0.0",
74+
"diffusers.utils.testing_utils is deprecated and will be removed in a future version. "
75+
"Determinism and device backend utilities have been moved to `diffusers.utils.torch_utils`. ",
7376
)
7477
_required_peft_version = is_peft_available() and version.parse(
7578
version.parse(importlib.metadata.version("peft")).base_version

tests/others/test_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
import importlib
1617
import os
1718
import unittest
19+
import warnings
1820

1921
import pytest
2022

@@ -182,6 +184,25 @@ def test_deprecate_stacklevel(self):
182184
assert str(warning.warning) == "This message is better!!!"
183185
assert "diffusers/tests/others/test_utils.py" in warning.filename
184186

187+
def test_deprecate_testing_utils_module(self):
188+
import diffusers.utils.testing_utils
189+
190+
with warnings.catch_warnings(record=True) as caught_warnings:
191+
warnings.simplefilter("always")
192+
importlib.reload(diffusers.utils.testing_utils)
193+
194+
deprecation_warnings = [w for w in caught_warnings if issubclass(w.category, FutureWarning)]
195+
assert len(deprecation_warnings) >= 1, "Expected at least one FutureWarning from diffusers.utils.testing_utils"
196+
197+
messages = [str(w.message) for w in deprecation_warnings]
198+
assert any("diffusers.utils.testing_utils" in msg for msg in messages), (
199+
f"Expected a deprecation warning mentioning 'diffusers.utils.testing_utils', got: {messages}"
200+
)
201+
assert any(
202+
"diffusers.utils.testing_utils is deprecated and will be removed in a future version." in msg
203+
for msg in messages
204+
), f"Expected deprecation message substring not found, got: {messages}"
205+
185206

186207
# Copied from https://github.com/huggingface/transformers/blob/main/tests/utils/test_expectations.py
187208
class ExpectationsTester(unittest.TestCase):

0 commit comments

Comments
 (0)