I am sorry for the dumb question, but I have been banging my head against a wall for past two hours.
I want to use relative imports and my project structure looks like this:
auto_testing
+ tests
+ __init__.py
+ my_module.py
+ src
+ __init__.py
+ my_module.py
+ __init__.py
The contents of tests/my_module.py are:
import unittest
from src.my_module import MyClass
class TestMyClass(unittest.TestCase):
def setUp(self):
self.inst = MyClass()
def test_division_by_zero(self):
self.assertRaises(ZeroDivisionError, self.inst.divide, 1, 0)
def run_tests():
unittest.main()
if __name__ == '__main__':
run_tests()
Then I run commands in terminal
cd auto_testing
python3 -m tests.my_module
and get Error while finding spec for 'tests.my_module.py' (<class 'AttributeError'>: 'module' object has no attribute '__path__').
When I run
cd auto_testing
python3
import tests.my_module
tests.my_module.run_tests()
I get Ran 0 tests (why no tests were found should be another question, but the point is, that MyClass is imported properly and unittest.main() seems to be called; checked with print).
Should I go sleeping for I missed something very simple?
Aucun commentaire:
Enregistrer un commentaire