No module named 'backend' [pytest coverage]

modulenotfounderror: no module named
python no module named same directory
no module named numpy
no module named python3
no module named requests
no module named pycharm
no module named project
no module named plumbum

I have a structure like this:

myProj
 --backend
   --app.py
 --tests
   --test_app.py

When i run the command:

pytest -v --cov=.tests/test_app

I get:

    tests/test_app.py:1: in <module>
    from backend.app import soma
E   ModuleNotFoundError: No module named 'backend'

Why can't import the library?

When the structure like this:

myProj
  --app.py
  --test_app.py

Perform correctly.

How can i run coverage in my project with the first showed structure ?

This is because backend is not a package.

To make it work as a package you should create an empty file named __init__.py inside the backend folder, so it will work as expected.

To read more about how packages work in Python, check the documentation.

Traps for the Unwary in Python's Import System — Nick Coghlan's , While Python 3.3+ is able to import the submodule without any problems: File " <string>", line 1, in <module> ImportError: No module named 'example.foo'. import module.py #incorrect output: ModuleNotFoundError: No module named 'module' core.py. import folder_1.module.py #correct output:Program finished with exit code 0 as you can see the problem has been solved. 3.The Library Module not installed. Also, you can get the issue if you are trying to import a module which not installed on your

ImportError: No module named 'XYZ' | by Yufeng, ImportError: No module named 'XYZ'. Jupyter notebook cannot find the package you already installed? Let's solve the problem. from toolkit.interface import interface ImportError: No module named toolkit.interface I have already checked sys.path and there I have the directory /site-packages . Also, I have the file __init__.py.bin in the toolkit folder to indicate to Python that this is a package.

As mentioned by @DiegoQueiroz and @HNMN3, you should make sure your directory as python package.

Add __init__.py file inside backend and tests directory.

Then, you need to mention module name in your command.

Given your project structure, you can input this command:

pytest -v --cov=backend.app tests/test_app

Python error “ImportError: No module named”, To get rid of this error you just need to create __init__.py in the appropriate directory and everything will work fine. To know more about this you� No module named 'mlxtend' Ask Question Asked 1 year ago. Active 6 months ago. Viewed 4k times 2. I am unable to install the mlextend package in Jupyter Python3

Python error “ImportError: No module named”, No module named”. 0 votes. My directory tree looks like this: (local directory)/ site-packages/toolkit/interface.py. My code is in here: ModuleNotFoundError: No module named 'discord' Ask Question Asked 2 years, 3 months ago. Active 1 year, 6 months ago. Viewed 4k times 0. Trying to run my .py file

ModuleNotFoundError: No module named 'CommandNotFound , line 8, in <module> from CommandNotFound.db.creator import DbCreator ModuleNotFoundError: No module named 'CommandNotFound'� When dealing with version ambiguity, remember that pip is a python module. Once you're confident that python is the python installation that your IDE is running, run. python --version python -m pip install seaborn >pip3 may be pointing to an old or different python installation.

ImportError: No module named github � Issue #856 � PyGithub , I'm trying to use PyGitHub and I'm getting "ImportError: No module named github". Setup specs: macOS v10.13.6 Python v3.7.0 Installed with� ModuleNotFoundError: No module named 'pip._internal' – Wajih Katrou May 29 '19 at 13:23 So it means pip itself not reinstalled properly. – Harsha Biyani May 29 '19 at 13:25

Comments
  • Yeah! Thank you very much! But, don't work 100%, now i get: tests/test_app.py ... [100%] Coverage.py warning: Module tests/test_app was never imported. (module-not-imported) Coverage.py warning: No data was collected. (no-data-collected) WARNING: Failed to generate report: No data to report. More anything tip?
  • You should understand whats wrong with the test package you're using. I'm not a heavy user of pytest documentation but I don't see a parameter named --cov in the documentation to simulate your scenario.
  • Yeah! Thank you very much! But, don't work 100%, now i get: tests/test_app.py ... [100%] Coverage.py warning: Module tests/test_app was never imported. (module-not-imported) Coverage.py warning: No data was collected. (no-data-collected) WARNING: Failed to generate report: No data to report.
  • More anything tip?
  • I think this is a separate issue and not related to the import of module. As per the logs it seems that code is running but not using the test_app. To solve that you need to update the code here. I would recommend to create another question with all the details of your code.