mirror of https://github.com/django/django.git
Fixed #28610 -- Skipped test when serializer is not available
Thanks Tim Graham for the review.
This commit is contained in:
parent
d549b88050
commit
774f5548bd
|
@ -1,7 +1,7 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import partialmethod
|
from functools import partialmethod
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from unittest import mock
|
from unittest import mock, skipIf
|
||||||
|
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.core.serializers import SerializerDoesNotExist
|
from django.core.serializers import SerializerDoesNotExist
|
||||||
|
@ -393,16 +393,16 @@ class SerializersTransactionTestBase:
|
||||||
self.assertEqual(art_obj.author.name, "Agnes")
|
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
|
Dynamically create serializer tests to ensure that all registered
|
||||||
serializers are automatically tested.
|
serializers are automatically tested.
|
||||||
"""
|
"""
|
||||||
formats = [
|
for format_ in serializers.get_serializer_formats():
|
||||||
f for f in serializers.get_serializer_formats()
|
if format_ == 'geojson' or format_ in exclude:
|
||||||
if (not isinstance(serializers.get_serializer(f), serializers.BadSerializer) and
|
continue
|
||||||
f != 'geojson' and
|
decorated_func = skipIf(
|
||||||
(exclude is None or f not in exclude))
|
isinstance(serializers.get_serializer(format_), serializers.BadSerializer),
|
||||||
]
|
'The Python library for the %s serializer is not installed.' % format_,
|
||||||
for format_ in formats:
|
)(test_func)
|
||||||
setattr(test_class, method_name % format_, partialmethod(test_func, format_))
|
setattr(test_class, method_name % format_, partialmethod(decorated_func, format_))
|
||||||
|
|
Loading…
Reference in New Issue