Skip to content

Commit 89f6d01

Browse files
author
Lucas Gameiro
authored
[DPE-4068] Finish test migration from unittest to pytest + enable/disable secrets in every test (#451)
* first effort * finish migration to pytest * remove print statement * add conftest with has_secrets fixture * fix commit email * fix lint * fix copyright year * refactor asserts
1 parent b9405e0 commit 89f6d01

File tree

9 files changed

+1883
-1750
lines changed

9 files changed

+1883
-1750
lines changed

tests/unit/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2024 Canonical Ltd.
3+
# See LICENSE file for licensing details.
4+
from unittest.mock import PropertyMock
5+
6+
import pytest
7+
8+
9+
# This causes every test defined in this file to run 2 times, each with
10+
# charm.JujuVersion.has_secrets set as True or as False
11+
@pytest.fixture(params=[True, False], autouse=True)
12+
def _has_secrets(request, monkeypatch):
13+
monkeypatch.setattr("charm.JujuVersion.has_secrets", PropertyMock(return_value=request.param))
14+
return request.param

tests/unit/test_backups.py

Lines changed: 704 additions & 677 deletions
Large diffs are not rendered by default.

tests/unit/test_charm.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,6 @@ def harness():
4848
harness.cleanup()
4949

5050

51-
# This causes every test defined in this file to run 2 times, each with
52-
# charm.JujuVersion.has_secrets set as True or as False
53-
@pytest.fixture(params=[True, False], autouse=True)
54-
def _has_secrets(request, monkeypatch):
55-
monkeypatch.setattr("charm.JujuVersion.has_secrets", PropertyMock(return_value=request.param))
56-
return request.param
57-
58-
5951
@patch_network_get(private_address="1.1.1.1")
6052
def test_on_install(harness):
6153
with patch("charm.subprocess.check_call") as _check_call, patch(

0 commit comments

Comments
 (0)