From a7f53f8e2e74c7e533079223812ad85cb9ab66c6 Mon Sep 17 00:00:00 2001 From: Peter Baughman Date: Mon, 23 Dec 2019 06:23:38 -0800 Subject: [PATCH] Import test file without contaminating sys.modules (#360) Signed-off-by: Pete Baughman --- launch_testing/launch_testing/launch_test.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/launch_testing/launch_testing/launch_test.py b/launch_testing/launch_testing/launch_test.py index e9a84d6bc..0a855f6bb 100644 --- a/launch_testing/launch_testing/launch_test.py +++ b/launch_testing/launch_testing/launch_test.py @@ -13,7 +13,7 @@ # limitations under the License. import argparse -from importlib.machinery import SourceFileLoader +import importlib.util import logging import os import sys @@ -28,9 +28,10 @@ def _load_python_file_as_module(test_module_name, python_file_path): """Load a given Python launch file (by path) as a Python module.""" - # Taken from launch_testing to not introduce a weird dependency thing - loader = SourceFileLoader(test_module_name, python_file_path) - return loader.load_module() + spec = importlib.util.spec_from_file_location(test_module_name, python_file_path) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module def add_arguments(parser):