-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
config.getini returns an empty list for an option of type string absent in INI file #11282
Comments
Here is an actual reproducer:
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")
def test_x(my_option):
assert my_option is None results in: def test_x(my_option):
> assert my_option is None
E assert [] is None |
Hello @harmin-parra, @The-Compiler, @Zac-HD, I can work on this fix if you all agree. Regards |
Hello all, I have a question regarding this issue. Should config.getini() return "None" irrespective of the "type" provided for the configuration? What if the the "type" is linelist or pathlist with no default value or "None" provided in configuration or while making the call to parser.addini() Please look at a test that exists in the current code base that implicitly assumes that the configuration item named "xy" has a default value of empty list. I think the correct way to call parser.addini() is to always provide a default value if you are expecting it to return an Empty List or any other data type. Which means the call to addini() in the test code below should be: parser.addini("xy", "", type="linelist", default=[])
Please let me know your views as there are some occurrences within the code base that makes this assumption of implicit default values based on "type". Regards |
the issue lies in pytest/src/_pytest/config/__init__.py Lines 1521 to 1528 in b73b4c4
it tries to be smart based on type, but does not quite deal with all kinds of types correctly as far as i can tell there also is the case of automatically returning "" on a empty default for a string when no type was defined (none implies string) maybe using something like dataclasses.Missing as a experiment to see how to make sane default return values could be a starting point |
Thank you @RonnyPfannschmidt, But my question was around the expected behavior after making changes for this issue. This issue as raised by @harmin-parra expects config.getini() to return "None" if "None" is set as the default value while adding the configuration item using parser.addini(). Solution 1 Solution 2 Solution 3
Please let me know which approach would be more acceptable? Regards |
I personally feel, Solution 1 is the right way to go considering the straight forward and clean approach. regards |
+1 for solution 1 We should return |
I also agree that The source code of The default value for the So I don't understand why the unit test checks for |
pytest 8.0 modified the handling of default parameter when defining configuration options, which breaks the use of 'pytest-postgresql < 4'. Workaround that issue by explicitly defining postgresql_load option in pytest.ini file. See pytest-dev/pytest#11282.
I want to manage this INI option
I decide not to include this option in the INI file
I read the value with this code
Actual result: The returned value is an empty list
Expected result: None
Tested with pytest 7.4.0 on Linux Mint
The text was updated successfully, but these errors were encountered: