From 774f5548bdf976fc6f0f5ec3603723850a698f74 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 18 Sep 2017 10:06:01 +0200 Subject: [PATCH] Fixed #28610 -- Skipped test when serializer is not available Thanks Tim Graham for the review. --- tests/serializers/tests.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/serializers/tests.py b/tests/serializers/tests.py index 0ad95f7397..0ea60f0f64 100644 --- a/tests/serializers/tests.py +++ b/tests/serializers/tests.py @@ -1,7 +1,7 @@ from datetime import datetime from functools import partialmethod from io import StringIO -from unittest import mock +from unittest import mock, skipIf from django.core import serializers from django.core.serializers import SerializerDoesNotExist @@ -393,16 +393,16 @@ class SerializersTransactionTestBase: self.assertEqual(art_obj.author.name, "Agnes") -def register_tests(test_class, method_name, test_func, exclude=None): +def register_tests(test_class, method_name, test_func, exclude=()): """ Dynamically create serializer tests to ensure that all registered serializers are automatically tested. """ - formats = [ - f for f in serializers.get_serializer_formats() - if (not isinstance(serializers.get_serializer(f), serializers.BadSerializer) and - f != 'geojson' and - (exclude is None or f not in exclude)) - ] - for format_ in formats: - setattr(test_class, method_name % format_, partialmethod(test_func, format_)) + for format_ in serializers.get_serializer_formats(): + if format_ == 'geojson' or format_ in exclude: + continue + decorated_func = skipIf( + isinstance(serializers.get_serializer(format_), serializers.BadSerializer), + 'The Python library for the %s serializer is not installed.' % format_, + )(test_func) + setattr(test_class, method_name % format_, partialmethod(decorated_func, format_))