Skip to content

Commit

Permalink
Add tests to prove new docstring
Browse files Browse the repository at this point in the history
For full context see issue pytest-dev#10558
  • Loading branch information
sus-pe committed Oct 13, 2024
1 parent 18a9817 commit 02402ee
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ def test_config_trace(self, pytester: Pytester) -> None:
assert len(values) == 1
assert values[0] == "hello [config]\n"

def test_config_getoption(self, pytester: Pytester) -> None:
def test_config_getoption_declared_option_name(self, pytester: Pytester) -> None:
pytester.makeconftest(
"""
def pytest_addoption(parser):
Expand All @@ -648,6 +648,18 @@ def pytest_addoption(parser):
assert config.getoption(x) == "this"
pytest.raises(ValueError, config.getoption, "qweqwe")

config_novalue = pytester.parseconfig()
assert config_novalue.getoption("hello") is None
assert config_novalue.getoption("hello", default=1) is None
assert config_novalue.getoption("hello", default=1, skip=True) == 1

def test_config_getoption_undeclared_option_name(self, pytester: Pytester) -> None:
config = pytester.parseconfig()
with pytest.raises(ValueError):
config.getoption("x")
assert config.getoption("x", default=1) == 1
assert config.getoption("x", default=1, skip=True) == 1

def test_config_getoption_unicode(self, pytester: Pytester) -> None:
pytester.makeconftest(
"""
Expand Down Expand Up @@ -675,12 +687,6 @@ def pytest_addoption(parser):
with pytest.raises(pytest.skip.Exception):
config.getvalueorskip("hello")

def test_getoption(self, pytester: Pytester) -> None:
config = pytester.parseconfig()
with pytest.raises(ValueError):
config.getvalue("x")
assert config.getoption("x", 1) == 1

def test_getconftest_pathlist(self, pytester: Pytester, tmp_path: Path) -> None:
somepath = tmp_path.joinpath("x", "y", "z")
p = tmp_path.joinpath("conftest.py")
Expand Down

0 comments on commit 02402ee

Please sign in to comment.