diff --git a/conan/tools/cmake/cmake.py b/conan/tools/cmake/cmake.py index 4139447819d..cc991cb464f 100644 --- a/conan/tools/cmake/cmake.py +++ b/conan/tools/cmake/cmake.py @@ -11,6 +11,7 @@ from conans.errors import ConanException from conans.model.version import Version from conans.util.conan_v2_mode import conan_v2_error +from conans.util.env_reader import get_env from conans.util.files import mkdir diff --git a/conans/client/build/cmake.py b/conans/client/build/cmake.py index 927d5535b54..f9b9b2fa0fa 100644 --- a/conans/client/build/cmake.py +++ b/conans/client/build/cmake.py @@ -20,6 +20,7 @@ from conans.model.version import Version from conans.util.conan_v2_mode import conan_v2_error from conans.util.config_parser import get_bool_from_text +from conans.util.env_reader import get_env from conans.util.files import mkdir, get_abs_path, walk, decode_text from conans.util.runners import version_runner @@ -330,7 +331,7 @@ def install(self, args=None, build_dir=None): self._build(args=args, build_dir=build_dir, target="install") def test(self, args=None, build_dir=None, target=None, output_on_failure=False): - if not self._conanfile.should_test: + if not self._conanfile.should_test or not get_env("CONAN_RUN_TESTS", True): return if not target: target = "RUN_TESTS" if self.is_multi_configuration else "test" diff --git a/conans/client/build/meson.py b/conans/client/build/meson.py index 6a8960d17f9..beb718add05 100644 --- a/conans/client/build/meson.py +++ b/conans/client/build/meson.py @@ -12,6 +12,7 @@ from conans.model.build_info import DEFAULT_BIN, DEFAULT_INCLUDE, DEFAULT_LIB from conans.model.version import Version from conans.util.conan_v2_mode import conan_v2_error +from conans.util.env_reader import get_env from conans.util.files import decode_text, get_abs_path, mkdir from conans.util.runners import version_runner @@ -225,7 +226,7 @@ def install(self, args=None, build_dir=None): self._run_ninja_targets(args=args, build_dir=build_dir, targets=["install"]) def test(self, args=None, build_dir=None, targets=None): - if not self._conanfile.should_test: + if not self._conanfile.should_test or not get_env("CONAN_RUN_TESTS", True): return if not targets: targets = ["test"] @@ -237,7 +238,7 @@ def meson_install(self, args=None, build_dir=None): self._run_meson_command(subcommand='install', args=args, build_dir=build_dir) def meson_test(self, args=None, build_dir=None): - if not self._conanfile.should_test: + if not self._conanfile.should_test or not get_env("CONAN_RUN_TESTS", True): return self._run_meson_command(subcommand='test', args=args, build_dir=build_dir) diff --git a/conans/test/unittests/client/build/cmake_test.py b/conans/test/unittests/client/build/cmake_test.py index 34fe9d83e60..298f19a85d4 100644 --- a/conans/test/unittests/client/build/cmake_test.py +++ b/conans/test/unittests/client/build/cmake_test.py @@ -184,6 +184,15 @@ def test_should_flags(self): CMakeTest.scape(". --target test -- -j%i" % cpu_count(output=conanfile.output)), conanfile.command) + def test_conan_run_tests(self): + conanfile = ConanFileMock() + conanfile.settings = Settings() + conanfile.should_test = True + cmake = CMake(conanfile, generator="Unix Makefiles") + with tools.environment_append({"CONAN_RUN_TESTS": "0"}): + cmake.test() + self.assertIsNone(conanfile.command) + def test_cmake_generator(self): conanfile = ConanFileMock() conanfile.settings = Settings() diff --git a/conans/test/unittests/client/build/meson_test.py b/conans/test/unittests/client/build/meson_test.py index a5f0901ab03..158695ba365 100644 --- a/conans/test/unittests/client/build/meson_test.py +++ b/conans/test/unittests/client/build/meson_test.py @@ -8,7 +8,7 @@ from conans.client.build import defs_to_string from conans.client.build.meson import Meson from conans.client.conf import get_default_settings_yml -from conans.client.tools import args_to_string +from conans.client.tools import args_to_string, environment_append from conans.errors import ConanException from conans.model.settings import Settings from conans.test.utils.mocks import MockDepsCppInfo, ConanFileMock @@ -51,6 +51,15 @@ def test_partial_build(self): meson.meson_install() self.assertIsNone(conan_file.command) + def test_conan_run_tests(self): + conan_file = ConanFileMock() + conan_file.settings = Settings() + conan_file.should_test = True + meson = Meson(conan_file) + with environment_append({"CONAN_RUN_TESTS": "0"}): + meson.test() + self.assertIsNone(conan_file.command) + def test_folders(self): settings = Settings.loads(get_default_settings_yml()) settings.os = "Linux"