Python ModuleNotFoundError for Custom Module

Viewed 1672

I am importing a custom module called as Helper to my unittest. When I run with the help of test explorer it works fine, but when I try to run through command line it give me below error. ModuleNotFoundError: No module named 'Helper' I have manually added empty init.py file at each directory and at project level as well. My python version is : 3.8.3 Below is the error I get in CMD. error while running through command line Here is my folder structure ,result and code when I execute through test explorer. sampleTest.py code

globalHelper.py globalHelper.py code

1 Answers

first of no need for empty __init__.py files in those other directories. Now to import a module that is in a directory use:

from dir_name.module_name import what_you_need

hope I did not mess up some terms and that you understood what I meant

Related