Skip to content

Commit

Permalink
better error message for wrong options definition (#13207)
Browse files Browse the repository at this point in the history
  • Loading branch information
memsharded authored Feb 23, 2023
1 parent e4ad406 commit e7a16ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion conans/model/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ def copy_conaninfo_options(self):
result = Options()
result._package_options = self._package_options.copy_conaninfo_options()
# In most scenarios this should be empty at this stage, because it was cleared
assert not self._deps_package_options
if self._deps_package_options:
raise ConanException("Dependencies options were defined incorrectly. Maybe you"
" tried to define options values in 'requirements()' or other"
" invalid place")
return result

def update(self, options=None, options_values=None):
Expand Down
17 changes: 17 additions & 0 deletions conans/test/integration/conanfile/conanfile_errors_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,20 @@ class HelloConan(ConanFile):
client.save(files)
client.run("export .")
assert "hello/0.1: Exported" in client.out


def test_requirements_change_options():
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
class HelloConan(ConanFile):
name = "hello"
version = "0.1"
def requirements(self):
self.options["mydep"].myoption = 3
""")
c.save({"conanfile.py": conanfile})
c.run("create .", assert_error=True)
assert "Dependencies options were defined incorrectly." in c.out

0 comments on commit e7a16ea

Please sign in to comment.