1+ import warnings
12from collections import OrderedDict , defaultdict
23from textwrap import dedent
34from unittest .mock import patch
@@ -399,15 +400,16 @@ class Meta:
399400 with pytest .warns (
400401 UserWarning ,
401402 match = r"Field name .* matches an attribute on Django model .* but it's not a model field" ,
402- ) as record :
403+ ):
403404
404405 class Reporter2 (DjangoObjectType ):
405406 class Meta :
406407 model = ReporterModel
407408 fields = ["first_name" , "some_method" , "email" ]
408409
409410 # Don't warn if selecting a custom field
410- with pytest .warns (None ) as record :
411+ with warnings .catch_warnings ():
412+ warnings .simplefilter ("error" )
411413
412414 class Reporter3 (DjangoObjectType ):
413415 custom_field = String ()
@@ -416,8 +418,6 @@ class Meta:
416418 model = ReporterModel
417419 fields = ["first_name" , "custom_field" , "email" ]
418420
419- assert len (record ) == 0
420-
421421
422422@with_local_registry
423423def test_django_objecttype_exclude_fields_exist_on_model ():
@@ -445,15 +445,14 @@ class Meta:
445445 exclude = ["custom_field" ]
446446
447447 # Don't warn on exclude fields
448- with pytest .warns (None ) as record :
448+ with warnings .catch_warnings ():
449+ warnings .simplefilter ("error" )
449450
450451 class Reporter4 (DjangoObjectType ):
451452 class Meta :
452453 model = ReporterModel
453454 exclude = ["email" , "first_name" ]
454455
455- assert len (record ) == 0
456-
457456
458457@with_local_registry
459458def test_django_objecttype_neither_fields_nor_exclude ():
@@ -467,24 +466,22 @@ class Reporter(DjangoObjectType):
467466 class Meta :
468467 model = ReporterModel
469468
470- with pytest .warns (None ) as record :
469+ with warnings .catch_warnings ():
470+ warnings .simplefilter ("error" )
471471
472472 class Reporter2 (DjangoObjectType ):
473473 class Meta :
474474 model = ReporterModel
475475 fields = ["email" ]
476476
477- assert len (record ) == 0
478-
479- with pytest .warns (None ) as record :
477+ with warnings .catch_warnings ():
478+ warnings .simplefilter ("error" )
480479
481480 class Reporter3 (DjangoObjectType ):
482481 class Meta :
483482 model = ReporterModel
484483 exclude = ["email" ]
485484
486- assert len (record ) == 0
487-
488485
489486def custom_enum_name (field ):
490487 return f"CustomEnum{ field .name .title ()} "
0 commit comments