From 1b8152efc7b5dad580f0e4b5929a8a2f65a0645a Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 8 Aug 2019 00:00:16 +0800 Subject: [PATCH] [Add] skip some tests if module not built --- tests/test_import_all.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_import_all.py b/tests/test_import_all.py index 6ebe6e78..3175aec5 100644 --- a/tests/test_import_all.py +++ b/tests/test_import_all.py @@ -8,6 +8,13 @@ def check_env(key: str, default=None): return environ.get(key, default) +def skip_if_module_not_built(env_key: str): + return unittest.skipIf( + check_env(key=env_key) == '0', + f"Skip because of {env_key}==0", + ) + + # noinspection PyUnresolvedReferences,PyMethodMayBeStatic class CoreImportTest(unittest.TestCase): @@ -34,6 +41,7 @@ class GatewayImportTest(unittest.TestCase): from vnpy.gateway.bitmex import BitmexGateway @unittest.skipIf(platform.system() == "Darwin", "Not supported yet under osx") + @skip_if_module_not_built(env_key="VNPY_BUILD_CTP") def test_import_ctp(self): from vnpy.gateway.ctp import CtpGateway @@ -60,7 +68,7 @@ class GatewayImportTest(unittest.TestCase): from vnpy.gateway.ib import IbGateway @unittest.skipIf(platform.system() == "Darwin", "Not supported yet under osx") - @unittest.skipIf(check_env('VNPY_BUILD_OES') == '0', "Skip because of VNPY_BUILD_OES==0") + @skip_if_module_not_built(env_key="VNPY_BUILD_OES") def test_import_oes(self): from vnpy.gateway.oes import OesGateway