Python import from parent directory

前端 未结 5 1227
渐次进展
渐次进展 2020-12-08 05:02

I have the following:

         ModuleFolder
              |
              |-->. ModuleFile.py .
              |
              \'-->. TestsFolder .
             


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 05:58

    My suggestion is:

    Don't try to be clever, do what you're supposed to do. I.e. make sure that your modules and packages are somewhere in your Python path.

    The simplest way is to set the environment variable PYTHONPATH in the shell that you use to execute your scripts:

    $ export PYTHONPATH=/the/directory/where/your/modules/and/packages/are
    $ cd /the/directory/where/your/unit/tests/are
    $ python test1.py
    

提交回复
热议问题