From a9215b7c36bff232bcc9416309726290dc74a9e8 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Sat, 2 Jul 2016 14:42:15 +0200 Subject: [PATCH] Refs #21548 -- Skipped tests that rely on pillow when it's not installed --- tests/validators/tests.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/validators/tests.py b/tests/validators/tests.py index 56dea8804f..459324fb74 100644 --- a/tests/validators/tests.py +++ b/tests/validators/tests.py @@ -6,7 +6,7 @@ import os import re import types from datetime import datetime, timedelta -from unittest import TestCase +from unittest import TestCase, skipUnless from django.core.exceptions import ValidationError from django.core.files.base import ContentFile @@ -23,6 +23,13 @@ from django.test import SimpleTestCase from django.test.utils import str_prefix from django.utils._os import upath +try: + from PIL import Image # noqa +except ImportError: + PILLOW_IS_INSTALLED = False +else: + PILLOW_IS_INSTALLED = True + NOW = datetime.now() EXTENDED_SCHEMES = ['http', 'https', 'ftp', 'ftps', 'git', 'file', 'git+ssh'] @@ -299,6 +306,9 @@ def create_simple_test_method(validator, expected, value, num): else: val_name = validator.__class__.__name__ test_name = test_mask % (val_name, num) + if validator is validate_image_file_extension: + SKIP_MSG = "Pillow is required to test validate_image_file_extension" + test_func = skipUnless(PILLOW_IS_INSTALLED, SKIP_MSG)(test_func) return test_name, test_func # Dynamically assemble a test class with the contents of TEST_DATA