pythonpython-unittest

Unittest can't find imported module in imported module


Unittest modules import issue

My project folder structure goes like this:

project/
  __init__.py (empty)
  tests/
    __init__.py (empty)
    tests.py
  src/
    __init__.py
    a.py
    b.py
    c.py      

tests/tests.py

import unittest
from a import A

my_a = A()
class TestClass(unittest.TestCase):
    # Some tests
    pass

src/init.py

__all__ = ["a", "b", "c"]

src/a.py

from b import B

src/b.py

from c import C

src/c.py

pass

Everything works fine when I run the code from the command line but testing it throws this error: ModuleNotFoundError: No module named 'b'

I did lots of research that I could condensed to these links:

Right now I'm really confused about how __init__.py would work in this case and why my test can't find imported modules path. Can anyone lend me a hand with this please?


Solution

  • from .b import B

    from .c import C