@@ -636,7 +636,7 @@ def test_config_trace(self, pytester: Pytester) -> None:
636
636
assert len (values ) == 1
637
637
assert values [0 ] == "hello [config]\n "
638
638
639
- def test_config_getoption (self , pytester : Pytester ) -> None :
639
+ def test_config_getoption_declared_option_name (self , pytester : Pytester ) -> None :
640
640
pytester .makeconftest (
641
641
"""
642
642
def pytest_addoption(parser):
@@ -648,6 +648,18 @@ def pytest_addoption(parser):
648
648
assert config .getoption (x ) == "this"
649
649
pytest .raises (ValueError , config .getoption , "qweqwe" )
650
650
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
+
651
663
def test_config_getoption_unicode (self , pytester : Pytester ) -> None :
652
664
pytester .makeconftest (
653
665
"""
@@ -675,12 +687,6 @@ def pytest_addoption(parser):
675
687
with pytest .raises (pytest .skip .Exception ):
676
688
config .getvalueorskip ("hello" )
677
689
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
-
684
690
def test_getconftest_pathlist (self , pytester : Pytester , tmp_path : Path ) -> None :
685
691
somepath = tmp_path .joinpath ("x" , "y" , "z" )
686
692
p = tmp_path .joinpath ("conftest.py" )
0 commit comments