Skip to content

Commit 9a7684e

Browse files
authored
Add test showing that you can update default option values from init() (#17234)
1 parent 98a7976 commit 9a7684e

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/integration/py_requires/python_requires_test.py

+43
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,49 @@ def generate(self):
832832
assert "OptionBASE: True" in c.out
833833
assert "OptionDERIVED: False" in c.out
834834

835+
def test_options_default_update(self):
836+
c = TestClient(light=True)
837+
base = textwrap.dedent("""
838+
from conan import ConanFile
839+
class BaseConan:
840+
options = {"base": [True, False]}
841+
default_options = {"base": True}
842+
843+
class PyReq(ConanFile):
844+
name = "base"
845+
version = "1.0.0"
846+
package_type = "python-require"
847+
""")
848+
derived = textwrap.dedent("""
849+
import conan
850+
851+
class DerivedConan(conan.ConanFile):
852+
name = "derived"
853+
python_requires = "base/1.0.0"
854+
python_requires_extend = "base.BaseConan"
855+
options = {"derived": [True, False]}
856+
default_options = {"derived": False}
857+
858+
def init(self):
859+
base = self.python_requires["base"].module.BaseConan
860+
self.options.update(base.options, base.default_options)
861+
self.options.base = False
862+
863+
def generate(self):
864+
self.output.info(f"OptionBASE: {self.options.base}")
865+
self.output.info(f"OptionDERIVED: {self.options.derived}")
866+
""")
867+
c.save({"base/conanfile.py": base,
868+
"derived/conanfile.py": derived})
869+
c.run("create base")
870+
c.run("install derived")
871+
assert "OptionBASE: False" in c.out
872+
assert "OptionDERIVED: False" in c.out
873+
874+
c.run("install derived -o=&:base=True")
875+
assert "OptionBASE: True" in c.out
876+
assert "OptionDERIVED: False" in c.out
877+
835878

836879
def test_transitive_python_requires():
837880
# https://github.com/conan-io/conan/issues/8546

0 commit comments

Comments
 (0)