title: python importlib, how to invalidate cache of dynamically loaded file
body: <p>Given this code, how can I tell python to not use cached sources or reload?</p>
  
  <pre><code>import importlib.util
  
  spec = importlib.util.spec_from_file_location('test', '~/myfile.py')
  test = importlib.util.module_from_spec(spec)
  spec.loader.exec_module(test)
  
  test.do_stuff()
  </code></pre>
  
  <p>when the content of myfile.py changes its not picked up, I'm assuming because it's cached. calling <code>importlib.invalidate_caches()</code> did not  help and <code>importlib.reload</code> results in an error saying test is not in sys.modules</p>