diff --git a/conans/model/conf.py b/conans/model/conf.py index 9140be00a31..a9664b891cd 100644 --- a/conans/model/conf.py +++ b/conans/model/conf.py @@ -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): diff --git a/test/unittests/model/test_conf.py b/test/unittests/model/test_conf.py index f0d155a74f9..841a87bf7d4 100644 --- a/test/unittests/model/test_conf.py +++ b/test/unittests/model/test_conf.py @@ -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