Closed areysset closed 1 year ago
Importing whatever method or class from fastoad (ex: from fastoad.module_management import constants) even if not used leads to a working test with no error.
When launching the test, I get the same error message with some more information (maybe because I use Python 3.8?): there may be a circular import.
E ImportError: cannot import name 'ComputeMachInterpolation' from partially initialized module 'fastga.models.aerodynamics.components' (most likely due to a circular import) (D:\cdavid\PycharmP
rojects\FAST-GA\src\fastga\models\aerodynamics\components\__init__.py)
I guess the problem is that FAST-OAD loads plugins (and by doing so, does the Python imports) as soon as it is loaded. And because of that, the "time" when you import the fastoad package matters.
If you do this import before everything else, all your code is scanned by Python at this time and all goes fine. But if you do this import "later", there goes the cycle. More specifically, your test imports your aerodynamics
package, and while it follows all the import chain, it comes to an import of fastoad
, which triggers the loading of plugins, which triggers an import of all your code... including the aerodynamics
package.
A fix in FAST-OAD maybe to delay the loading of plugins to ensure it is done only when needed. It may be a good thing also because it should speed up some operations (it is annoying to wait for the loading process when doing just fastoad -h
in CLI).
In the meantime, the workaround I can suggest is to ensure fastoad
is loaded before any test.
It can be done by adding the pytest "pre-processing" file conftest.py
at the root of your project with this simple content:
import fastoad
PR #409 may fix this problem, since it actually delays the loading of plugins. To be confirmed...
As anticipated, PR #409 fixes this issue (tests done on plugin_error
branch ).
With the update of the dependencies of FAST-GA to FAST-OAD-core, some unit tests can't run because some group that are tested are using submodels which cannot be loaded. The solution is to add an instance of the FASTOADLoader inside the conftest.py
This problem is only with unit tests, with an existing solution as described above. Closing the issue.
Describe the bug Some unitary tests exhib top_level_collect errors due to plugin behavior and relative imports. By letting an unused import in the unitary test file (un-commented) : from fastoad.io import VariableIO, permits to avoid the error but the reason behind is not clear to me. We would like a clear explanation about what can be done about import: relative/absolute....
To Reproduce Dowload the relative branch from FASTGA and launch unitary tests on aerodynamics models.
Expected behavior With or without the unused import line commented, the code should work fine.
Error message
Environment
Additional context Add any other context about the problem here.