Skip to content
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

Failing test for unset conf #17445

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def get(self, conf_name, default=None, check_type=None, choices=None):
conf_value = self._values.get(conf_name)
if conf_value:
v = conf_value.value
if choices is not None and v not in choices:
if choices is not None and v not in choices and v is not None:
raise ConanException(f"Unknown value '{v}' for '{conf_name}'")
# Some smart conversions
if check_type is bool and not isinstance(v, bool):
Expand Down
19 changes: 19 additions & 0 deletions test/unittests/model/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,22 @@ def test_conf_scope_patterns_bad(scope, conf, assert_message):
c.loads(final_conf)
c.validate()
assert assert_message in str(exc_info.value)


@pytest.mark.parametrize("choices", [None, ["Foo", "Bar"]])
def test_unset_basic_same_behaviour(choices):
c = ConfDefinition()
assert c.get("user.company.cpu:jobs", choices=choices) is None

c2 = ConfDefinition()
c2.loads("user.company.cpu:jobs=!")
assert c2.get("user.company.cpu:jobs", choices=choices) is None

c3 = ConfDefinition()
c3.loads("user.company.cpu:jobs=4")

c4 = ConfDefinition()
c4.loads("user.company.cpu:jobs=!")
c3.update_conf_definition(c4)

assert c3.get("user.company.cpu:jobs", choices=choices) is None
Loading