Skip to content
New issue

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

test: handle warnings generated by our own tests #1469

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,6 @@ def test_storage_no_storage(self):

def test_storage_with_storage(self):
# here we patch juju_backend_available, so it gets set up and falls over when used
with patch('ops.storage.juju_backend_available') as juju_backend_available:
juju_backend_available.return_value = True
with pytest.raises(FileNotFoundError, match='state-get'):
self._check(ops.CharmBase, use_juju_for_storage=True)

def test_controller_storage_deprecated(self):
with patch('ops.storage.juju_backend_available') as juju_backend_available:
juju_backend_available.return_value = True
with pytest.warns(DeprecationWarning, match='Controller storage'):
Expand Down
6 changes: 4 additions & 2 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3643,11 +3643,13 @@ def test_from_dict(self):
assert info.rotates is None
assert info.description is None

info = ops.SecretInfo.from_dict('5', {'revision': 9})
with pytest.warns(DeprecationWarning, match='`model_uuid` should always be provided'):
info = ops.SecretInfo.from_dict('5', {'revision': 9})
assert info.id == 'secret:5'
assert info.revision == 9

info = ops.SecretInfo.from_dict('secret://abcd/6', {'revision': 9})
with pytest.warns(DeprecationWarning, match='`model_uuid` should always be provided'):
info = ops.SecretInfo.from_dict('secret://abcd/6', {'revision': 9})
assert info.id == 'secret://abcd/6'
assert info.revision == 9

Expand Down
1 change: 1 addition & 0 deletions testing/src/scenario/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def secret_info_get(
expires=secret.expire,
rotation=secret.rotate,
rotates=None, # not implemented yet.
model_uuid=self._state.model.uuid,
)

def secret_set(
Expand Down
21 changes: 19 additions & 2 deletions testing/tests/test_context_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ def _on_event(self, event):
("update_status", ops.UpdateStatusEvent),
("config_changed", ops.ConfigChangedEvent),
("upgrade_charm", ops.UpgradeCharmEvent),
("pre_series_upgrade", ops.PreSeriesUpgradeEvent),
("post_series_upgrade", ops.PostSeriesUpgradeEvent),
("leader_elected", ops.LeaderElectedEvent),
],
)
Expand All @@ -71,6 +69,25 @@ def test_simple_events(event_name, event_kind):
assert isinstance(mgr.charm.observed[0], event_kind)


@pytest.mark.parametrize(
"event_name, event_kind",
[
("pre_series_upgrade", ops.PreSeriesUpgradeEvent),
("post_series_upgrade", ops.PostSeriesUpgradeEvent),
],
)
def test_simple_deprecated_events(event_name, event_kind):
ctx = scenario.Context(ContextCharm, meta=META, actions=ACTIONS)
# These look like:
# ctx.run(ctx.on.pre_series_upgrade(), state)
with pytest.warns(DeprecationWarning):
with ctx(getattr(ctx.on, event_name)(), scenario.State()) as mgr:
mgr.run()
assert len(mgr.charm.observed) == 2
assert isinstance(mgr.charm.observed[1], ops.CollectStatusEvent)
assert isinstance(mgr.charm.observed[0], event_kind)


@pytest.mark.parametrize("as_kwarg", [True, False])
@pytest.mark.parametrize(
"event_name,event_kind,owner",
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ deps =
-e .
-e testing
commands =
pytest -n auto --ignore={[vars]tst_path}smoke -v --tb native {posargs}
pytest -n auto --ignore={[vars]tst_path}smoke -v --tb native \
-W 'ignore:Harness is deprecated:PendingDeprecationWarning' {posargs}

[testenv:coverage]
description = Run unit tests with coverage
Expand Down
Loading