Skip to content

Commit

Permalink
Bug Fix 11282: config.getini returns an empty list for an option of t…
Browse files Browse the repository at this point in the history
…ype string absent in INI file
  • Loading branch information
TanyaAgarwal28 committed Oct 11, 2023
1 parent 1d6a6d9 commit cfa662e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
14 changes: 0 additions & 14 deletions testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,6 @@ def pytester(pytester: Pytester, monkeypatch: MonkeyPatch) -> Pytester:
return pytester


def pytest_addoption(parser):
parser.addini(
"my_option",
type="string",
default=None,
help="My option",
)


@pytest.fixture(scope="session")
def my_option(request):
return request.config.getini("my_option")


@pytest.fixture(scope="session")
def color_mapping():
"""Returns a utility class which can replace keys in strings in the form "{NAME}"
Expand Down
40 changes: 33 additions & 7 deletions testing/test_conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,40 @@ def test_setinitial_conftest_subdirs(pytester: Pytester, name: str) -> None:


def test_my_option(pytester: Pytester):
p = pytester.makepyfile(
"""
def test_x(my_option):
assert my_option is None
"""
testdir = pytester.mkdir("test_my_option")
conftest_content = """\
import pytest
def pytest_addoption(parser):
parser.addini(
"my_option",
type="string",
default=None,
help="My option",
)
@pytest.fixture(scope='session')
def my_option(request):
return request.config.getini("my_option")
"""
# Place conftest.py in the root directory of the project
testdir.parent.joinpath("conftest.py").write_text(
conftest_content, encoding="utf-8"
)
result = pytester.runpytest(p)
result.assert_outcomes(failed=0, passed=1)

# Create a simple test function
test_content = """\
def test_example(my_option):
assert my_option is None
"""
testdir.joinpath("test_my_option.py").write_text(test_content, encoding="utf-8")
result = pytester.runpytest(
str(testdir.parent)
) # Run pytest from the root directory
assert result.ret == 0


def test_conftest_confcutdir(pytester: Pytester) -> None:
Expand Down

0 comments on commit cfa662e

Please sign in to comment.