mardi 23 mai 2017

why use relative import failed when import code from source package in test package

Here is the thing:

When you developing a project, and test the code, you don't want to copy the code to sys.path, I mean python site-packages.So you have to use relative import.

the structure is:

|- pymonitoringplusin

    |- ftp_ftplib.py

|- tests

    |- test_ftp.py

I want to import source code from develop path, not python site-packages.

Here is the code in test_ftp.py:

from ..pymonitoringplugins.ftp_ftplib.py import Ftp

But got error:

ValueError: Attempted relative import in non-package

Here is the source code:

http://ift.tt/2qU0MUo

Aucun commentaire:

Enregistrer un commentaire