Skip to content

Commit 29d9a48

Browse files
committed
Tests: Add option to clean up all resources provisioned to Grafana
1 parent 9868435 commit 29d9a48

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ in progress
1111
- Tests: Disable caching in test mode
1212
- Tests: Make test suite clean up its provisioned assets from Grafana
1313
- Tests: Run Grafana on non-standard port 33333
14+
- Tests: Add flag ``CLEANUP_RESOURCES`` to determine whether to clean up
15+
all resources provisioned to Grafana.
1416

1517

1618
2022-02-03 0.13.1

tests/conftest.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
from grafana_wtf.core import GrafanaWtf
1313

14+
# Whether to clean up all resources provisioned to Grafana.
15+
CLEANUP_RESOURCES = True
16+
1417

1518
# Make sure development or production settings don't leak into the test suite.
1619
def clean_environment():
@@ -78,9 +81,10 @@ def _create_datasource(name: str, type: str, access: str, **kwargs):
7881

7982
yield _create_datasource
8083

81-
if datasource_ids:
82-
for datasource_id in datasource_ids:
83-
grafana.datasource.delete_datasource_by_id(datasource_id)
84+
if CLEANUP_RESOURCES:
85+
if datasource_ids:
86+
for datasource_id in datasource_ids:
87+
grafana.datasource.delete_datasource_by_id(datasource_id)
8488

8589

8690
@pytest.fixture
@@ -141,9 +145,10 @@ def _create_folder(title: str, uid: str = None):
141145
yield _create_folder
142146

143147
# Delete dashboard again.
144-
if folder_uids:
145-
for folder_uid in folder_uids:
146-
grafana.folder.delete_folder(uid=folder_uid)
148+
if CLEANUP_RESOURCES:
149+
if folder_uids:
150+
for folder_uid in folder_uids:
151+
grafana.folder.delete_folder(uid=folder_uid)
147152

148153

149154
@pytest.fixture
@@ -182,9 +187,10 @@ def _create_dashboard(dashboard: dict = None, folder_id: str = None, folder_uid:
182187
yield _create_dashboard
183188

184189
# Delete dashboard again.
185-
if dashboard_uids:
186-
for dashboard_uid in dashboard_uids:
187-
grafana.dashboard.delete_dashboard(dashboard_uid=dashboard_uid)
190+
if CLEANUP_RESOURCES:
191+
if dashboard_uids:
192+
for dashboard_uid in dashboard_uids:
193+
grafana.dashboard.delete_dashboard(dashboard_uid=dashboard_uid)
188194

189195

190196
@pytest.fixture

0 commit comments

Comments
 (0)