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

Automatically handle CONAN_RUN_TESTS environment variable #8687

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions conan/tools/cmake/cmake.py
Expand Up @@ -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


Expand Down
3 changes: 2 additions & 1 deletion conans/client/build/cmake.py
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions conans/client/build/meson.py
Expand Up @@ -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

Expand Down Expand Up @@ -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"]
Expand All @@ -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)

Expand Down
9 changes: 9 additions & 0 deletions conans/test/unittests/client/build/cmake_test.py
Expand Up @@ -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()
Expand Down
11 changes: 10 additions & 1 deletion conans/test/unittests/client/build/meson_test.py
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down