I have the following project structure:
main.py
mainpackage/
|---tests__/
|---test_module1.py
|---package1/
|--- module1.py
|---paackage2/
|--- module2.py
my test_module1.py looks like this:
import unittest
from ..package1.module1 import toTest
class MyTest(unittest.Testcase):
def test_mytest(self):
fu = toTest()
self.assertEqual(fu,2)
#more tests omitted
if __name__ == "__main__"
unittest.main()
But when I run this inside tests
python test_module1.py I obviously get the following error:
ImportError: attempted relative import with no known parent package
But when I move to the folder mainpackage/ and run this:
python -m unittest discover -t .. -v mainpackage.tests.test_module
it runs all tests in that file. However I can not just pick one test of that file. I tried this:
python -m unittest discover -t .. -v mainpackage.tests.test_module.MyTest.test_mytest
Which gave me the following error:
ImportError: Start directory is not importable: