@@ -636,7 +636,7 @@ def test_config_trace(self, pytester: Pytester) -> None:
636636 assert len (values ) == 1
637637 assert values [0 ] == "hello [config]\n "
638638
639- def test_config_getoption (self , pytester : Pytester ) -> None :
639+ def test_config_getoption_declared_option_name (self , pytester : Pytester ) -> None :
640640 pytester .makeconftest (
641641 """
642642 def pytest_addoption(parser):
@@ -648,6 +648,18 @@ def pytest_addoption(parser):
648648 assert config .getoption (x ) == "this"
649649 pytest .raises (ValueError , config .getoption , "qweqwe" )
650650
651+ config_novalue = pytester .parseconfig ()
652+ assert config_novalue .getoption ("hello" ) is None
653+ assert config_novalue .getoption ("hello" , default = 1 ) is None
654+ assert config_novalue .getoption ("hello" , default = 1 , skip = True ) == 1
655+
656+ def test_config_getoption_undeclared_option_name (self , pytester : Pytester ) -> None :
657+ config = pytester .parseconfig ()
658+ with pytest .raises (ValueError ):
659+ config .getoption ("x" )
660+ assert config .getoption ("x" , default = 1 ) == 1
661+ assert config .getoption ("x" , default = 1 , skip = True ) == 1
662+
651663 def test_config_getoption_unicode (self , pytester : Pytester ) -> None :
652664 pytester .makeconftest (
653665 """
@@ -675,12 +687,6 @@ def pytest_addoption(parser):
675687 with pytest .raises (pytest .skip .Exception ):
676688 config .getvalueorskip ("hello" )
677689
678- def test_getoption (self , pytester : Pytester ) -> None :
679- config = pytester .parseconfig ()
680- with pytest .raises (ValueError ):
681- config .getvalue ("x" )
682- assert config .getoption ("x" , 1 ) == 1
683-
684690 def test_getconftest_pathlist (self , pytester : Pytester , tmp_path : Path ) -> None :
685691 somepath = tmp_path .joinpath ("x" , "y" , "z" )
686692 p = tmp_path .joinpath ("conftest.py" )
0 commit comments