Skip to content

Commit

Permalink
Import test file without contaminating sys.modules (#360)
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Baughman <[email protected]>
  • Loading branch information
Peter Baughman authored and ivanpauno committed Jan 17, 2020
1 parent 7f3da8c commit a7f53f8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions launch_testing/launch_testing/launch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import argparse
from importlib.machinery import SourceFileLoader
import importlib.util
import logging
import os
import sys
Expand All @@ -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):
Expand Down

0 comments on commit a7f53f8

Please sign in to comment.