mercredi 25 mars 2020

Python Tests - ValueError: attempted relative import beyond top-level package

Given the following folder structure:

|-- README.md
|-- packages
|   `-- mypackge
|       |-- __init__.py
|       |-- base.py
|       |-- module1.py
|       `-- tests
|           `-- test_module.py
|-- project.py
`-- requirements.txt

While firing:

$ packages/mypackge/tests: python test_module.py

inside test_module.py I import using:

from ..mypackage.module1 import *

The following error is shown:

ImportError: attempted relative import with no known parent package

How can I fix so I can fire the test and it will import the package that I want to test?

Aucun commentaire:

Enregistrer un commentaire