title: how to programmatically change a variable in a python package to run test
body: <p>I have a project structure something like this. I want to write a test which programmatically change <strong>version</strong> variable in myPackage/version.py and write a test in tests/unit/test_release.py.</p>
  <pre><code>├── myPackage
  │   ├── __init__.py
  │   ├── root.py
  │   └── version.py
  └── tests
      └── unit
          └── test_release.py
  </code></pre>
  <p>cat myPackage/<strong>init</strong>.py</p>
  <pre><code>from .version import __version__
  </code></pre>
  <p>cat myPackage/root.py</p>
  <pre><code>from .version import __version__
  def printFunc():
    return __version__
  
  if __name__ == &quot;__main__&quot;:
    print(printFunc())
  </code></pre>
  <p>cat myPackage/version.py</p>
  <pre><code>__version__ = '5.7.11'
  </code></pre>
  <p>cat tests/unit/test_release.py</p>
  <pre><code>import sys
  sys.path.insert(0, &quot;/Users/username/myfolder&quot;)
  
  from myPackage import root, version
  import unittest
  
  class TestHelp(unittest.TestCase):
      def setUp(self):
          pass
  
      def test_version(self):
        version.__version__ = '7.8.19'
        new_version = root.printFunc()
        assert new_version == '7.8.19'
  </code></pre>
  <p>What is the best way to do that?</p>