@@ -445,6 +445,7 @@ def test_warn_if_called_incorrectly() -> None:
445445def test_warn_if_spec_does_not_have_method () -> None :
446446 """It should trigger a warning if bound_args is called incorrectly."""
447447 class_subject = SpyCore (source = SomeClass , name = None )
448+ nested_class_subject = SpyCore (source = SomeNestedClass , name = None )
448449 func_subject = SpyCore (source = some_func , name = None )
449450 specless_subject = SpyCore (source = None , name = "anonymous" )
450451
@@ -458,6 +459,29 @@ def test_warn_if_spec_does_not_have_method() -> None:
458459 warnings .simplefilter ("error" )
459460 class_subject .create_child_core ("foo" , False )
460461
462+ # property access without types should not warn
463+ with warnings .catch_warnings ():
464+ warnings .simplefilter ("error" )
465+ class_subject .create_child_core ("mystery_property" , False )
466+
467+ # property access should be allowed through optionals
468+ with warnings .catch_warnings ():
469+ warnings .simplefilter ("error" )
470+ parent = nested_class_subject .create_child_core ("optional_child" , False )
471+ parent .create_child_core ("primitive_property" , False )
472+
473+ # property access should be allowed through None unions
474+ with warnings .catch_warnings ():
475+ warnings .simplefilter ("error" )
476+ parent = nested_class_subject .create_child_core ("union_none_child" , False )
477+ parent .create_child_core ("primitive_property" , False )
478+
479+ # property access should not be checked through unions
480+ with warnings .catch_warnings ():
481+ warnings .simplefilter ("error" )
482+ parent = nested_class_subject .create_child_core ("union_child" , False )
483+ parent .create_child_core ("who_knows" , False )
484+
461485 # incorrect class usage should warn
462486 with pytest .warns (
463487 MissingSpecAttributeWarning , match = "has no attribute 'this_is_wrong'"
@@ -469,3 +493,17 @@ def test_warn_if_spec_does_not_have_method() -> None:
469493 MissingSpecAttributeWarning , match = "has no attribute 'this_is_wrong'"
470494 ):
471495 func_subject .create_child_core ("this_is_wrong" , False )
496+
497+ # incorrect nested property usage should warn
498+ with pytest .warns (
499+ MissingSpecAttributeWarning , match = "has no attribute 'this_is_wrong'"
500+ ):
501+ parent = nested_class_subject .create_child_core ("optional_child" , False )
502+ parent .create_child_core ("this_is_wrong" , False )
503+
504+ # incorrect nested property usage should warn
505+ with pytest .warns (
506+ MissingSpecAttributeWarning , match = "has no attribute 'this_is_wrong'"
507+ ):
508+ parent = nested_class_subject .create_child_core ("union_none_child" , False )
509+ parent .create_child_core ("this_is_wrong" , False )
0 commit comments