使用
-
姜戈:1.11
-
蟒蛇3.6
-
图纸编号:3.7
-
Drest(又名动态休息):1.8
我有一个这样写的序列化程序:
class SubProjectAsFKWithAttachedFieldsSerializer(DynamicModelSerializer):
# attached_fields = AttachedFieldSerializer(embed=True, many=True)
try:
scope_object = UgField.objects.get(dotted_path='global.scope')
scopes = DynamicRelationField(
AttachedFieldWithDirectValuesSerializer,
source='attached_fields',
many=True,
embed=True,
read_only=True,
queryset=AttachedField.objects.filter(ug_field=scope_object)
)
except ObjectDoesNotExist:
scopes = DynamicRelationField(AttachedFieldWithDirectValuesSerializer,
source='attached_fields',
many=True,
read_only=True,
embed=True)
目前,几乎所有我的
tests.py
在设置方法中,我有
self.global_scope_field = UgFieldFactory(dotted_path='global.scope', name='Scope')
出于某种原因,这条线
scope_object = UgField.objects.get(dotted_path='global.scope')
尽管我已经使用
DjangoModelFactory
我应该怎么做才能确保在运行测试时行总是通过?
更新
-
只是为了指出我实际上有一个ugfield记录,它有一个字符串
global.scope
作为字段的值
dotted_path
.
-
只有当我跑步时
python manage.py test
我要面对这个问题吗?
-
当我正确运行应用程序时,没有问题。
我也试过设置
(self.global_scope_field, created) = UgField.objects.get_or_create(dotted_path='global.scope', name='Scope')
在我的
setUp
方法。
但后来我又遇到了同样的问题