@@ -848,6 +848,82 @@ def pytest_addoption(parser):
848
848
config = pytester .parseconfig ()
849
849
assert config .getini ("strip" ) is bool_val
850
850
851
+ @pytest .mark .parametrize ("str_val, int_val" , [("10" , 10 ), ("no-ini" , 2 )])
852
+ def test_addini_int (self , pytester : Pytester , str_val : str , int_val : bool ) -> None :
853
+ pytester .makeconftest (
854
+ """
855
+ def pytest_addoption(parser):
856
+ parser.addini("ini_param", "", type="int", default=2)
857
+ """
858
+ )
859
+ if str_val != "no-ini" :
860
+ pytester .makeini (
861
+ f"""
862
+ [pytest]
863
+ ini_param={ str_val }
864
+ """
865
+ )
866
+ config = pytester .parseconfig ()
867
+ assert config .getini ("ini_param" ) == int_val
868
+
869
+ def test_addini_int_invalid (self , pytester : Pytester ) -> None :
870
+ pytester .makeconftest (
871
+ """
872
+ def pytest_addoption(parser):
873
+ parser.addini("ini_param", "", type="int", default=2)
874
+ """
875
+ )
876
+ pytester .makepyprojecttoml (
877
+ """
878
+ [tool.pytest.ini_options]
879
+ ini_param=["foo"]
880
+ """
881
+ )
882
+ config = pytester .parseconfig ()
883
+ with pytest .raises (
884
+ TypeError , match = "Expected an int string for option ini_param"
885
+ ):
886
+ _ = config .getini ("ini_param" )
887
+
888
+ @pytest .mark .parametrize ("str_val, float_val" , [("10.5" , 10.5 ), ("no-ini" , 2.2 )])
889
+ def test_addini_float (
890
+ self , pytester : Pytester , str_val : str , float_val : bool
891
+ ) -> None :
892
+ pytester .makeconftest (
893
+ """
894
+ def pytest_addoption(parser):
895
+ parser.addini("ini_param", "", type="float", default=2.2)
896
+ """
897
+ )
898
+ if str_val != "no-ini" :
899
+ pytester .makeini (
900
+ f"""
901
+ [pytest]
902
+ ini_param={ str_val }
903
+ """
904
+ )
905
+ config = pytester .parseconfig ()
906
+ assert config .getini ("ini_param" ) == float_val
907
+
908
+ def test_addini_float_invalid (self , pytester : Pytester ) -> None :
909
+ pytester .makeconftest (
910
+ """
911
+ def pytest_addoption(parser):
912
+ parser.addini("ini_param", "", type="float", default=2.2)
913
+ """
914
+ )
915
+ pytester .makepyprojecttoml (
916
+ """
917
+ [tool.pytest.ini_options]
918
+ ini_param=["foo"]
919
+ """
920
+ )
921
+ config = pytester .parseconfig ()
922
+ with pytest .raises (
923
+ TypeError , match = "Expected a float string for option ini_param"
924
+ ):
925
+ _ = config .getini ("ini_param" )
926
+
851
927
def test_addinivalue_line_existing (self , pytester : Pytester ) -> None :
852
928
pytester .makeconftest (
853
929
"""
0 commit comments