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

better error message for wrong options definition #13207

Merged
merged 1 commit into from
Feb 23, 2023
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
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