title: Function to import modules from a list
body: <p>My goal is to have a function with a list of strings as input and import those modules I want for my code.</p>
  <p>Example:</p>
  <pre><code>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
  </code></pre>
  <p>I have tried this solution and it seems like the modules are not imported. I have also tried using <strong>import</strong> builtin function, but nothing.</p>
  <p>My real example was:</p>
  <pre><code>def importer(modules):
      for value in modules:
          if value == &quot;ble_connection&quot;:
              from top_app.module.connection.test_connectivity import connection1
          if value == &quot;switch_connection&quot;:
              from top_app.module.connection.test_connectivity import connection2
  </code></pre>
  <p>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.</p>
  <p>Do you have any solution for this?</p>
  <p>thanks</p>