Home > Blockchain >  __init__.py issue in django test
__init__.py issue in django test

Time:12-03

I have an issue with running a test in my Django project, using the command python manage.py test. It shows:

user:~/workspace/connector$ docker-compose run --rm app sh -c "python manage.py test"
Creating connector_app_run ... done
Found 0 test(s).
System check identified no issues (0 silenced).

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

I was debugging it and I know that it's probably a "init.py" file.

If I'm deleting file init.py from app.app (I have read somewhere that it can help) then I'm receiving an error:

======================================================================
ERROR: app.tests.test_secrets (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: app.tests.test_secrets
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/local/lib/python3.9/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/app/app/tests/test_secrets.py", line 12, in <module>
    from app.app import secrets
ModuleNotFoundError: No module named 'app.app'

why did this error occur? Pycharm projects normally see import and what I know from version 3.4 it's not obligatory to put init.py into folders to make the package.

This is the github link:

https://github.com/MrHarvvey/connector.git

Can you explain me what I'm I doing wrong here?

CodePudding user response:

So as per your project file structure, I changed from app.app import secrets to from app import secrets and then found test cases are also failing, so I fixed them also, you can review the changes here:

https://github.com/MrHarvvey/connector/pull/1

Please let me know you if you wanted something else.

  • Related