Bug Fix 11282: config.getini returns an empty list for an option of type string absent in INI file
This commit is contained in:
parent
888e9e82d2
commit
b61719d479
|
@ -223,37 +223,24 @@ def test_setinitial_conftest_subdirs(pytester: Pytester, name: str) -> None:
|
||||||
|
|
||||||
def test_my_option(pytester: Pytester):
|
def test_my_option(pytester: Pytester):
|
||||||
testdir = pytester.mkdir("test_my_option")
|
testdir = pytester.mkdir("test_my_option")
|
||||||
testdir.joinpath("conftest.py").write_text(
|
conftest_content = """
|
||||||
textwrap.dedent(
|
def pytest_addoption(parser):
|
||||||
"""\
|
parser.addini(
|
||||||
def pytest_addoption(parser):
|
"my_option",
|
||||||
parser.addini(
|
type="string",
|
||||||
"my_option",
|
default=None,
|
||||||
type="string",
|
help="My option",
|
||||||
default=None,
|
)
|
||||||
help="My option",
|
"""
|
||||||
)
|
testdir.joinpath("conftest.py").write_text(conftest_content, encoding="utf-8")
|
||||||
@pytest.fixture(scope='session')
|
|
||||||
def my_option(request):
|
|
||||||
return request.config.getini("my_option")
|
|
||||||
"""
|
|
||||||
),
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
# Create a simple test function
|
# Create a simple test function
|
||||||
testdir.joinpath("test_my_option.py").write_text(
|
test_content = """
|
||||||
textwrap.dedent(
|
def test_example(my_option):
|
||||||
"""\
|
assert my_option is None
|
||||||
def test_example(my_option):
|
"""
|
||||||
assert my_option is None
|
testdir.joinpath("test_my_option.py").write_text(test_content, encoding="utf-8")
|
||||||
"""
|
|
||||||
),
|
|
||||||
encoding="utf-8",
|
|
||||||
)
|
|
||||||
result = pytester.runpytest(str(testdir))
|
result = pytester.runpytest(str(testdir))
|
||||||
assert result.ret == 0
|
assert result.ret == 0
|
||||||
captured_stdout = result.stdout.str()
|
|
||||||
assert "1 passed" in captured_stdout
|
|
||||||
|
|
||||||
|
|
||||||
def test_conftest_confcutdir(pytester: Pytester) -> None:
|
def test_conftest_confcutdir(pytester: Pytester) -> None:
|
||||||
|
|
Loading…
Reference in New Issue