Question

I am trying to import a file in current directory but i am getting something like this

 module_not_in_the_pythonpath__

for all the variables that i have defined in that file.

i have added the path

      C:/Project/main_test_folder

in the python-path

My directory structure is like this.

 main_test_folder
       test_folder1             //working fine here
              __init__.py
              Constants.py
              Some test file Constant.py will be imported.
       test_folder2            //working fine here
              __init__.py
              Constants.py
              //Some test file Constant.py will be imported.
       test_folder3              //for this folder alone its not working
              __init__.py
              Constants.py
              Common.py          //Constant.py is imported in this(not working)
              Testcase.py
              //Some more test file ,Constant.py,Common.py will be imported in each file.

Common.py

     from constants import *
     class Payload(object):


         def __init__(self, params):
            '''
            Constructor
            '''
         @staticmethod
         def createPayLoad(Name,model):  //NAME and MODEL Defined in constants.py
              PAYLOAD_PROFILE={
                 NAME:              Name,
                 MODEL:                     model,

                 }

            return PAYLOAD

Testcase.py

     from common import *        //this line is not working
     from constants import *

Error :

   test_folder3\test_01_rename.py:15: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _  @staticmethod def   
   createPayLoad(Name, model): PAYLOAD={ > NAME: Name,MODEL: model} E NameError: global 
   name 'NAME' is not defined test_folder3\common .py:34: NameError</failure>
Was it helpful?

Solution

It's bad practice to use import * see
You can do so if you set the __ALL__ variable in your module's __init__.py see

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top