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

allow test_requires(..., force=True) #14394

Merged
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
8 changes: 4 additions & 4 deletions conans/model/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ class TestRequirements:
def __init__(self, requires):
self._requires = requires

def __call__(self, ref, run=None, options=None):
self._requires.test_require(ref, run=run, options=options)
def __call__(self, ref, run=None, options=None, force=None):
self._requires.test_require(ref, run=run, options=options, force=force)


class Requirements:
Expand Down Expand Up @@ -510,7 +510,7 @@ def override(self, ref):
req.override = True
self._requires[req] = req

def test_require(self, ref, run=None, options=None):
def test_require(self, ref, run=None, options=None, force=None):
"""
Represent a testing framework like gtest

Expand All @@ -526,7 +526,7 @@ def test_require(self, ref, run=None, options=None):
# libs = True => We need to link with it
# headers = True => We need to include it
req = Requirement(ref, headers=True, libs=True, build=False, run=run, visible=False,
test=True, package_id_mode=None, options=options)
test=True, package_id_mode=None, options=options, force=force)
if self._requires.get(req):
raise ConanException("Duplicated requirement: {}".format(ref))
self._requires[req] = req
Expand Down
21 changes: 21 additions & 0 deletions conans/test/integration/graph/test_test_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ def requirements(self):
"engine/1.0": "Cache"})
c.assert_listed_require({"gtest/1.0": "Cache"}, test=True)

def test_test_requires_conflict_force(self):
c = TestClient()
game = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
def requirements(self):
self.test_requires("gtest/1.0", force=True)
self.test_requires("rapidcheck/1.0")
""")
c.save({"gtest/conanfile.py": GenConanfile("gtest"),
"rapidcheck/conanfile.py":
GenConanfile("rapidcheck", "1.0").with_requires("gtest/1.1"),
"game/conanfile.py": game
})
c.run("create gtest --version=1.0")
c.run("create gtest --version=1.1")
c.run("create rapidcheck")
c.run("install game")
c.assert_listed_require({"gtest/1.0": "Cache"}, test=True)
c.assert_overrides({"gtest/1.1": ["gtest/1.0#08dd14dd79315dd95c94b85d13bd1388"]})


def test_require_options():
c = TestClient()
Expand Down