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