1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Unittest can't find imported module in imported module

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    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?

    Continue reading...

Compartilhe esta Página