canonical / operator

Pure Python framework for writing Juju charms
Apache License 2.0
245 stars 119 forks source link

Scenario related ImportError errors with ops 2.16.0 #1353

Closed gruyaume closed 2 months ago

gruyaume commented 2 months ago

Overview

We get scenario related ImportError errors after bumping ops from 2.15.0 to 2.16.0. This issue prevents all of our projects from using this latest version of ops.

Logs

Traceback (most recent call last):
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/pytest/__main__.py", line [9](https://github.com/canonical/sdcore-udr-k8s-operator/actions/runs/10669457294/job/29571434981?pr=300#step:4:10), in <module>
    raise SystemExit(pytest.console_main())
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.[10](https://github.com/canonical/sdcore-udr-k8s-operator/actions/runs/10669457294/job/29571434981?pr=300#step:4:11)/site-packages/_pytest/config/__init__.py", line 201, in console_main
    code = main()
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/config/__init__.py", line 156, in main
    config = _prepareconfig(args, plugins)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/config/__init__.py", line 341, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/pluggy/_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/pluggy/_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/pluggy/_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/helpconfig.py", line 105, in pytest_cmdline_parse
    config = yield
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/pluggy/_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/config/__init__.py", line [11](https://github.com/canonical/sdcore-udr-k8s-operator/actions/runs/10669457294/job/29571434981?pr=300#step:4:12)40, in pytest_cmdline_parse
    self.parse(args)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1490, in parse
    self._preparse(args, addopts=addopts)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1377, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/pluggy/_manager.py", line 421, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 171, in load
    module = import_module(match.group('module'))
  File "/usr/lib/python3.10/importlib/__init__.py", line [12](https://github.com/canonical/sdcore-udr-k8s-operator/actions/runs/10669457294/job/29571434981?pr=300#step:4:13)6, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 174, in exec_module
    exec(co, module.__dict__)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/interface_tester/__init__.py", line 5, in <module>
    from interface_tester.interface_test import Tester
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/_pytest/assertion/rewrite.py", line 174, in exec_module
    exec(co, module.__dict__)
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/interface_tester/interface_test.py", line 16, in <module>
    from scenario import Context, Event, Relation, State, state
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/scenario/__init__.py", line 4, in <module>
    from scenario.context import ActionOutput, Context
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/scenario/context.py", line [13](https://github.com/canonical/sdcore-udr-k8s-operator/actions/runs/10669457294/job/29571434981?pr=300#step:4:14), in <module>
    from scenario.runtime import Runtime
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/scenario/runtime.py", line 19, in <module>
    from scenario.ops_main_mock import NoObserverError
  File "/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/scenario/ops_main_mock.py", line 17, in <module>
    from ops.main import CHARM_STATE_FILE, _Dispatcher, _get_charm_dir, _get_event_args
ImportError: cannot import name '_get_charm_dir' from 'ops.main' (/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/ops/main.py)
/home/runner/work/sdcore-upf-k8s-operator/sdcore-upf-k8s-operator/.tox/unit/lib/python3.10/site-packages/coverage/control.py:894: CoverageWarning: No data was collected. (no-data-collected)
  self._warn("No data was collected.", slug="no-data-collected")

References

Here are a couple of examples of CI where this error was observed.

tonyandrewmeyer commented 2 months ago

You need to be using at least version 6.1.6 of Scenario with ops 2.16 (Scenario 6.1.6 will work with older ops as well). Scenario uses private parts of ops so is susceptible to breakage that charms aren't. We released 6.1.6 of Scenario before ops 2.16 so that people could upgrade Scenario first and not have any ops breakage.

Once we've completed the integration of Scenario into ops this cycle, this won't be an issue going forward.