def test_global_tools_overrided(self): client = TestClient() conanfile = """ from conans import ConanFile, tools class HelloConan(ConanFile): name = "Hello" version = "0.1" def build(self): assert(tools._global_requester != None) assert(tools._global_output != None) """ client.save({"conanfile.py": conanfile}) client.run("install .") client.run("build .") # Not test the real commmand get_command if it's setting the module global vars tmp = temp_folder() conf = default_client_conf.replace("\n[proxies]", "\n[proxies]\nhttp = http://myproxy.com") os.mkdir(os.path.join(tmp, ".conan")) save(os.path.join(tmp, ".conan", CONAN_CONF), conf) with tools.environment_append({"CONAN_USER_HOME": tmp}): conan_api, _, _ = ConanAPIV1.factory() conan_api.remote_list() global_output, global_requester = get_global_instances() self.assertEqual(global_requester.proxies, {"http": "http://myproxy.com"}) self.assertIsNotNone(global_output.warn)
def _configureConan(): ''' Ensures Conan is configured correctly so we can use its utility functionality from outside recipes ''' # We only need to perform configuration once if ConanTools._isConanConfigured == True: return # Ensure Conan's global configuration object is not `None` when using Conan 1.22.0 or newer if hasattr(tools, 'get_global_instances') and hasattr( tools, 'set_global_instances'): if 'config' in inspect.signature( tools.set_global_instances).parameters: instances = tools.get_global_instances() tools.set_global_instances(the_output=instances[0], the_requester=instances[1], config=_DummyConfig()) ConanTools._isConanConfigured = True