Skip to content

Commit

Permalink
new test_package_folder attribute (#16013)
Browse files Browse the repository at this point in the history
* new test_package_folder attribute

* fix
  • Loading branch information
memsharded committed Apr 5, 2024
1 parent 3483973 commit 1966e18
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion conan/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def create(conan_api, parser, *args):

cwd = os.getcwd()
path = conan_api.local.get_conanfile_path(args.path, cwd, py=True)
test_conanfile_path = _get_test_conanfile_path(args.test_folder, path)
overrides = eval(args.lockfile_overrides) if args.lockfile_overrides else None
lockfile = conan_api.lockfile.get_lockfile(lockfile=args.lockfile,
conanfile_path=path,
Expand Down Expand Up @@ -98,6 +97,9 @@ def create(conan_api, parser, *args):
lockfile = conan_api.lockfile.update_lockfile(lockfile, deps_graph, args.lockfile_packages,
clean=args.lockfile_clean)

test_package_folder = getattr(conanfile, "test_package_folder", None) \
if args.test_folder is None else args.test_folder
test_conanfile_path = _get_test_conanfile_path(test_package_folder, path)
# If the user provide --test-missing and the binary was not built from source, skip test_package
if args.test_missing and deps_graph.root.dependencies\
and deps_graph.root.dependencies[0].dst.binary != BINARY_BUILD:
Expand Down
30 changes: 30 additions & 0 deletions conans/test/integration/layout/test_layout_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,33 @@ def test(self):
"test_package/conanfile.py": conanfile})
c.run("create .")
assert f"build_folder in test_package: True" in c.out


class TestCustomTestPackage:
def test_custom_test_package(self):
c = TestClient(light=True)
conanfile = GenConanfile("pkg", "0.1").with_class_attribute('test_package_folder="mytest"')
c.save({"conanfile.py": conanfile,
"mytest/conanfile.py": GenConanfile().with_test("self.output.info('MYTEST!')"),
"mytest2/conanfile.py": GenConanfile().with_test("self.output.info('MYTEST2!')")})
c.run("create .")
assert "MYTEST!" in c.out
c.run("create . -tf=mytest2")
assert "MYTEST2!" in c.out

def test_custom_test_package_subfolder(self):
c = TestClient(light=True)
conanfile = GenConanfile("pkg", "0.1").with_class_attribute('test_package_folder="my/test"')
c.save({"pkg/conanfile.py": conanfile,
"pkg/my/test/conanfile.py": GenConanfile().with_test("self.output.info('MYTEST!')")})
c.run("create pkg")
assert "MYTEST!" in c.out

def test_custom_test_package_sibling(self):
c = TestClient(light=True)
conanfile = GenConanfile("pkg", "0.1").with_class_attribute(
'test_package_folder="../my/test"')
c.save({"pkg/conan/conanfile.py": conanfile,
"pkg/my/test/conanfile.py": GenConanfile().with_test("self.output.info('MYTEST!')")})
c.run("create pkg/conan")
assert "MYTEST!" in c.out

0 comments on commit 1966e18

Please sign in to comment.