@@ -4584,6 +4584,52 @@ def test_1(self, myfix):
45844584 reprec .assertoutcome (passed = 1 )
45854585
45864586
4587+ class TestGetReturnAnnotation :
4588+ def test_primitive_return_type (self ):
4589+ def six () -> int :
4590+ return 6
4591+
4592+ assert get_return_annotation (six ) == "int"
4593+
4594+ def test_compound_return_type (self ):
4595+ def two_sixes () -> tuple [int , str ]:
4596+ return (6 , "six" )
4597+
4598+ assert get_return_annotation (two_sixes ) == "tuple[int, str]"
4599+
4600+ def test_callable_return_type (self ):
4601+ def callable_return () -> Callable [..., Any ]:
4602+ return self .test_compound_return_type
4603+
4604+ assert get_return_annotation (callable_return ) == "Callable[..., Any]"
4605+
4606+ def test_no_annotation (self ):
4607+ def no_annotation ():
4608+ return 6
4609+
4610+ assert get_return_annotation (no_annotation ) == ""
4611+
4612+ def test_none_return_type (self ):
4613+ def none_return () -> None :
4614+ pass
4615+
4616+ assert get_return_annotation (none_return ) == "None"
4617+
4618+ def test_custom_class_return_type (self ):
4619+ class T :
4620+ pass
4621+ def class_return () -> T :
4622+ return T ()
4623+
4624+ assert get_return_annotation (class_return ) == "T"
4625+
4626+ def test_enum_return_type (self ):
4627+ def enum_return () -> ExitCode :
4628+ return ExitCode (0 )
4629+
4630+ assert get_return_annotation (enum_return ) == "ExitCode"
4631+
4632+
45874633def test_call_fixture_function_error ():
45884634 """Check if an error is raised if a fixture function is called directly (#4545)"""
45894635
@@ -5089,45 +5135,3 @@ def test_method(self, /, fix):
50895135 )
50905136 result = pytester .runpytest ()
50915137 result .assert_outcomes (passed = 1 )
5092-
5093-
5094- def test_get_return_annotation () -> None :
5095- def six () -> int :
5096- return 6
5097-
5098- assert get_return_annotation (six ) == "int"
5099-
5100- def two_sixes () -> tuple [int , str ]:
5101- return (6 , "six" )
5102-
5103- assert get_return_annotation (two_sixes ) == "tuple[int, str]"
5104-
5105- def callable_return () -> Callable [..., Any ]:
5106- return two_sixes
5107-
5108- assert get_return_annotation (callable_return ) == "Callable[..., Any]"
5109-
5110- def no_annotation ():
5111- return 6
5112-
5113- assert get_return_annotation (no_annotation ) == ""
5114-
5115- def none_return () -> None :
5116- pass
5117-
5118- assert get_return_annotation (none_return ) == "None"
5119-
5120- class T :
5121- pass
5122-
5123- def class_return () -> T :
5124- return T ()
5125-
5126- assert get_return_annotation (class_return ) == "T"
5127-
5128- def enum_return () -> ExitCode :
5129- return ExitCode (0 )
5130-
5131- assert get_return_annotation (enum_return ) == "ExitCode"
5132-
5133- assert get_return_annotation (range ) == ""
0 commit comments