0

I have a Python package with a directory that looks like this:

-root
 |
 |-src
 | |
 |  -app
 |   |
 |   |-__init__.py
 |   |-__main__.py
 |   |-file1.py
 |   |-file2.py
 |
 |-tests
   |
   |-__init__.py
   |-test_function.py

file1.py looks like this

from app import file2

def function():
    return file2.another_function()

test_function.py looks like this

import unittest

from src.app.file1 import function

class TestFunction(unittest.TestCase):
    def test_case(self):
        self.assertTrue(function())

However, whilst as a package this works fine, when running the test I get a ModuleNotFoundError: No module named 'app' on from app import file2.

It works when I put src. in front of app in file1.py but then the package breaks. Looking around, there isn't really a clear way to fix this so unsure what my path should be looking like.

2
  • 2
    what about from . import file2 ? Commented Jan 22 at 10:49
  • That's worked thank you! Commented Jan 22 at 11:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.