Skip to content

Commit

Permalink
test_requires shouldn't affect package_id (conan-io#13966)
Browse files Browse the repository at this point in the history
* test_requires shouldn't affect package_id

* test with transitive

* remove prints
  • Loading branch information
memsharded committed May 26, 2023
1 parent ad22ad3 commit d3d9fbf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conans/model/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,15 @@ def deduce_package_id_mode(self, pkg_type, dep_node, non_embed_mode, embed_mode,
if self.package_id_mode:
return

if self.test:
return # test_requires never affect the binary_id
dep_conanfile = dep_node.conanfile
dep_pkg_type = dep_conanfile.package_type
if self.build:
build_mode = getattr(dep_conanfile, "build_mode", build_mode)
if build_mode and self.direct:
self.package_id_mode = build_mode
return # At the moment no defaults
return

if pkg_type is PackageType.HEADER:
self.package_id_mode = "unrelated_mode"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest

from conans.test.utils.tools import GenConanfile, TestClient
from conans.util.files import save


@pytest.mark.parametrize("build_mode", [None, "patch_mode"])
def test_package_id_not_affected_test_requires(build_mode):
"""
By default, test_requires do not affect the package_id
"""
c = TestClient()
if build_mode is not None:
save(c.cache.new_config_path, "core.package_id:default_build_mode={build_mode}")
c.save({"gtest/conanfile.py": GenConanfile("gtest", "1.0"),
"engine/conanfile.py": GenConanfile("engine", "1.0").with_test_requires("gtest/1.0")})
c.run("create gtest")
c.run("create engine")
c.run("list engine:*")
assert "engine/1.0" in c.out
assert "gtest" not in c.out


def test_package_id_not_affected_test_requires_transitive():
"""
By default, transitive deps of test_requires do not affect the package_id
"""
c = TestClient()

c.save({"zlib/conanfile.py": GenConanfile("zlib", "1.0"),
"gtest/conanfile.py": GenConanfile("gtest", "1.0").with_requires("zlib/1.0"),
"engine/conanfile.py": GenConanfile("engine", "1.0").with_test_requires("gtest/1.0")})
c.run("create zlib")
c.run("create gtest")
c.run("create engine")
c.run("list engine:*")
assert "engine/1.0" in c.out
assert "gtest" not in c.out
assert "zlib" not in c.out

0 comments on commit d3d9fbf

Please sign in to comment.