title: unittest, works locally, but not on a remote server, no module named x.__main__; 'x' is a package and cannot be directly executed
body: <p>I am working on a Jenkins CI/CD pipeline for my Python package. My project file hierarchy is as follows:</p>
  <pre><code>project/
  - package_name
    - file1.py
    - file2.py
    - etc...
  - tests
    - unit
      - __main__.py
      - __init__.py
      - test1.py
      - test2.py
  </code></pre>
  <p>All unit tests (I am using <code>unittest</code>) are run using a single command</p>
  <p><code>python -m tests.unit</code></p>
  <p>via adding <code>__init__.py</code> of the following content:</p>
  <p><strong>contents</strong></p>
  <pre><code>import os
  os.chdir(os.path.dirname(os.path.abspath(__file__)))
  </code></pre>
  <p>and <code>__main__.py</code> which looks like this</p>
  <p><strong>contents</strong></p>
  <pre><code>import unittest
  import sys
  
  sys.path.append('../..')
  
  loader = unittest.TestLoader()
  start_dir = '.'
  suite = loader.discover(start_dir)
  runner = unittest.TextTestRunner(verbosity=2).run(suite)
  </code></pre>
  <p>First, the path is changed to the <code>./tests/unit</code>. After that, the top directory is added to the import path so that the package can be imported in tests. This works as intended (i.e., all rests are executed by running <code>python -m test.unit</code> at the top of the project directory) on my personal laptop (Python 3.6.4).</p>
  <p>However, when I use the same trick on a remote Jenkins server (Python 3.6.4 as well), I am getting the following error:</p>
  <pre><code>no module named test.unit.__main__; 'test.unit' is a package and cannot be directly executed
  </code></pre>
  <p>I have researched the issue but none of the proposed solutions seems to be working in my case.</p>
  <p><em>How can I modify my code to create a test suite in <code>unittest</code> that will run without any issues locally and remotely?</em></p>
  <p><strong>EDIT</strong>
  I tried modifying the <code>PYTHONPATH</code> variable, but no success</p>