We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Originally inspired by canonical/operator#307
tl;dr Harness and non-Harness tests are interfering with each other, so we should not access charm object directly, like we did before.
charm
We need to refactor an existing unit tests (e.g remove direct charm object references) to fix this:
======================================================================== FAILURES ======================================================================== _____________________________________________ OnConfigChangedHandlerTest.test__it_blocks_until_pod_is_ready ______________________________________________ self = <charm_test.OnConfigChangedHandlerTest testMethod=test__it_blocks_until_pod_is_ready> mock_pod_spec = <function set_juju_pod_spec at 0x7fb334d35f80>, mock_juju_pod_spec = <function build_juju_pod_spec at 0x7fb334d4c710> mock_time = <NonCallableMagicMock name='time' spec_set='module' id='140407662251216'> mock_k8s_mod = <NonCallableMagicMock name='k8s' spec_set='module' id='140407662251984'> mock_build_juju_unit_status_func = <function build_juju_unit_status at 0x7fb334d5e050> @patch('charm.build_juju_unit_status', spec_set=True, autospec=True) @patch('charm.k8s', spec_set=True, autospec=True) @patch('charm.time', spec_set=True, autospec=True) @patch('charm.build_juju_pod_spec', spec_set=True, autospec=True) @patch('charm.set_juju_pod_spec', spec_set=True, autospec=True) def test__it_blocks_until_pod_is_ready( self, mock_pod_spec, mock_juju_pod_spec, mock_time, mock_k8s_mod, mock_build_juju_unit_status_func): # Setup mock_fw_adapter_cls = \ create_autospec(framework.FrameworkAdapter, spec_set=True) mock_fw_adapter = mock_fw_adapter_cls.return_value mock_juju_unit_states = [ MaintenanceStatus(str(uuid4())), MaintenanceStatus(str(uuid4())), ActiveStatus(str(uuid4())), ] mock_build_juju_unit_status_func.side_effect = mock_juju_unit_states mock_event_cls = create_autospec(EventBase, spec_set=True) mock_event = mock_event_cls.return_value harness = Harness(charm.Charm) > harness.begin() test/charm_test.py:93: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ lib/ops/testing.py:121: in begin self._charm = TestCharm(self._framework, self._framework.meta.name) src/charm.py:39: in __init__ super().__init__(*args) lib/ops/charm.py:353: in __init__ self.on.define_event(relation_name + '_relation_created', RelationCreatedEvent) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ cls = <class 'ops.testing.Harness.begin.<locals>.TestEvents'>, event_kind = 'http_api_relation_created' event_type = <class 'ops.charm.RelationCreatedEvent'> @classmethod def define_event(cls, event_kind, event_type): """Define an event on this type at runtime. cls: a type to define an event on. event_kind: an attribute name that will be used to access the event. Must be a valid python identifier, not be a keyword or an existing attribute. event_type: a type of the event to define. """ prefix = 'unable to define an event with event_kind that ' if not event_kind.isidentifier(): raise RuntimeError(prefix + 'is not a valid python identifier: ' + event_kind) elif keyword.iskeyword(event_kind): raise RuntimeError(prefix + 'is a python keyword: ' + event_kind) try: getattr(cls, event_kind) raise RuntimeError( > prefix + 'overlaps with an existing type {} attribute: {}'.format(cls, event_kind)) E RuntimeError: unable to define an event with event_kind that overlaps with an existing type <class 'ops.testing.Harness.begin.<locals>.TestEvents'> attribute: http_api_relation_created lib/ops/framework.py:322: RuntimeError
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Originally inspired by canonical/operator#307
tl;dr Harness and non-Harness tests are interfering with each other, so we should not access
charm
object directly, like we did before.We need to refactor an existing unit tests (e.g remove direct
charm
object references) to fix this:The text was updated successfully, but these errors were encountered: