1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Refs #29522 -- Fixed serializers/fixtures test crash if PyYAML isn't installed.

This commit is contained in:
Mariusz Felisiak
2024-09-19 08:19:43 +02:00
committed by Sarah Boyce
parent f8cc9285e1
commit 1fa8493640
2 changed files with 25 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
import json
import os
import re
import unittest
from io import StringIO
from pathlib import Path
@@ -55,6 +56,13 @@ from .models import (
Widget,
)
try:
import yaml # NOQA
HAS_YAML = True
except ImportError:
HAS_YAML = False
_cur_dir = os.path.dirname(os.path.abspath(__file__))
@@ -96,11 +104,13 @@ class TestFixtures(TestCase):
the serialized data for fields that have been removed
from the database when not ignored.
"""
for fixture_file in (
test_fixtures = [
"sequence_extra",
"sequence_extra_jsonl",
"sequence_extra_yaml",
):
]
if HAS_YAML:
test_fixtures.append("sequence_extra_yaml")
for fixture_file in test_fixtures:
with (
self.subTest(fixture_file=fixture_file),
self.assertRaises(DeserializationError),
@@ -147,6 +157,7 @@ class TestFixtures(TestCase):
)
self.assertEqual(Animal.specimens.all()[0].name, "Eagle")
@unittest.skipUnless(HAS_YAML, "No yaml library detected")
def test_loaddata_not_found_fields_ignore_yaml(self):
management.call_command(
"loaddata",