My goal is to have a function with a list of strings as input and import those modules I want for my code.
Example:
list_of_modules = ['module1', 'module2']
def importer(list_of_modules):
for module in list_of_modules:
if module == 'module1':
from package.package2.module1 import function1
if module == 'module2':
from package.package2.module2 import function1
if module == 'module3':
from package.package2.module3 import function1
I have tried this solution and it seems like the modules are not imported. I have also tried using import builtin function, but nothing.
My real example was:
def importer(modules):
for value in modules:
if value == "ble_connection":
from top_app.module.connection.test_connectivity import connection1
if value == "switch_connection":
from top_app.module.connection.test_connectivity import connection2
I have to add that I am using pytest for running the tests from the general conftest file and this one calls this importer function during the pytest_configure hook which is right after the discovery hook.
Do you have any solution for this?
thanks