1
+ import warnings
1
2
from collections import OrderedDict , defaultdict
2
3
from textwrap import dedent
3
4
from unittest .mock import patch
@@ -399,15 +400,16 @@ class Meta:
399
400
with pytest .warns (
400
401
UserWarning ,
401
402
match = r"Field name .* matches an attribute on Django model .* but it's not a model field" ,
402
- ) as record :
403
+ ):
403
404
404
405
class Reporter2 (DjangoObjectType ):
405
406
class Meta :
406
407
model = ReporterModel
407
408
fields = ["first_name" , "some_method" , "email" ]
408
409
409
410
# Don't warn if selecting a custom field
410
- with pytest .warns (None ) as record :
411
+ with warnings .catch_warnings ():
412
+ warnings .simplefilter ("error" )
411
413
412
414
class Reporter3 (DjangoObjectType ):
413
415
custom_field = String ()
@@ -416,8 +418,6 @@ class Meta:
416
418
model = ReporterModel
417
419
fields = ["first_name" , "custom_field" , "email" ]
418
420
419
- assert len (record ) == 0
420
-
421
421
422
422
@with_local_registry
423
423
def test_django_objecttype_exclude_fields_exist_on_model ():
@@ -445,15 +445,14 @@ class Meta:
445
445
exclude = ["custom_field" ]
446
446
447
447
# Don't warn on exclude fields
448
- with pytest .warns (None ) as record :
448
+ with warnings .catch_warnings ():
449
+ warnings .simplefilter ("error" )
449
450
450
451
class Reporter4 (DjangoObjectType ):
451
452
class Meta :
452
453
model = ReporterModel
453
454
exclude = ["email" , "first_name" ]
454
455
455
- assert len (record ) == 0
456
-
457
456
458
457
@with_local_registry
459
458
def test_django_objecttype_neither_fields_nor_exclude ():
@@ -467,24 +466,22 @@ class Reporter(DjangoObjectType):
467
466
class Meta :
468
467
model = ReporterModel
469
468
470
- with pytest .warns (None ) as record :
469
+ with warnings .catch_warnings ():
470
+ warnings .simplefilter ("error" )
471
471
472
472
class Reporter2 (DjangoObjectType ):
473
473
class Meta :
474
474
model = ReporterModel
475
475
fields = ["email" ]
476
476
477
- assert len (record ) == 0
478
-
479
- with pytest .warns (None ) as record :
477
+ with warnings .catch_warnings ():
478
+ warnings .simplefilter ("error" )
480
479
481
480
class Reporter3 (DjangoObjectType ):
482
481
class Meta :
483
482
model = ReporterModel
484
483
exclude = ["email" ]
485
484
486
- assert len (record ) == 0
487
-
488
485
489
486
def custom_enum_name (field ):
490
487
return f"CustomEnum{ field .name .title ()} "
0 commit comments