equinor / ert

ERT - Ensemble based Reservoir Tool - is designed for running ensembles of dynamical models such as reservoir models, in order to do sensitivity analysis and data assimilation. ERT supports data assimilation using the Ensemble Smoother (ES), Ensemble Smoother with Multiple Data Assimilation (ES-MDA) and Iterative Ensemble Smoother (IES).
https://ert.readthedocs.io/en/latest/
GNU General Public License v3.0
103 stars 107 forks source link

Circular imports error when running gui.plottery tests #8840

Closed xjules closed 1 month ago

xjules commented 1 month ago

What happened? (You can include a screenshot if it helps explain)

When running pytest in gui/plottery on main we are getting circular imports error: For instance: pytest -svv tests/ert/unit_tests/gui/plottery/test_ensemble_plot.py will produce

ImportError while importing test module '/data/workspace/ert/tests/ert/unit_tests/gui/plottery/test_ensemble_plot.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/data/env/py311-std/lib64/python3.11/site-packages/_pytest/python.py:493: in importtestmodule
    mod = import_path(
/data/env/py311-std/lib64/python3.11/site-packages/_pytest/pathlib.py:582: in import_path
    importlib.import_module(module_name)
/usr/lib64/python3.11/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
    ???
<frozen importlib._bootstrap>:1176: in _find_and_load
    ???
<frozen importlib._bootstrap>:1147: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:690: in _load_unlocked
    ???
/data/env/py311-std/lib64/python3.11/site-packages/_pytest/assertion/rewrite.py:184: in exec_module
    exec(co, module.__dict__)
tests/ert/unit_tests/gui/plottery/test_ensemble_plot.py:7: in <module>
    from ert.gui.plottery import PlotConfig, PlotContext
src/ert/gui/plottery/__init__.py:13: in <module>
    from .plot_context import PlotContext  # noqa
src/ert/gui/plottery/plot_context.py:5: in <module>
    from ert.gui.tools.plot.plot_api import EnsembleObject
src/ert/gui/tools/plot/__init__.py:4: in <module>
    from .plot_tool import PlotTool
src/ert/gui/tools/plot/plot_tool.py:8: in <module>
    from .plot_window import PlotWindow
src/ert/gui/tools/plot/plot_window.py:13: in <module>
    from ert.gui.plottery import PlotConfig, PlotContext
E   ImportError: cannot import name 'PlotContext' from partially initialized module 'ert.gui.plottery' (most likely due to a circular import) (/data/workspace/ert/src/ert/gui/plottery/__init__.py)

It might be related to this commit: https://github.com/equinor/ert/commit/156e202efac9f112f189acbf53270e2fc31955ec

What did you expect to happen?

Just run pytest...

steps to reproduce

`pytest -svv tests/ert/unit_tests/gui/plottery/test_ensemble_plot.py`

Environment where bug has been observed