1
- from unittest import skipUnless
2
-
1
+ import pytest
2
+ from django . conf import settings
3
3
from django .db import connections
4
- from django .test import TestCase
5
4
6
5
from django_prometheus .testutils import (
7
6
assert_metric_compare ,
11
10
save_registry ,
12
11
)
13
12
13
+ # @pytest.fixture(autouse=True)
14
+ # def enable_db_access_for_all_tests(db):
15
+ # pass
16
+
14
17
15
- class BaseDbMetricTest ( TestCase ):
16
- # https://docs.djangoproject.com/en/2.2/topics/testing/tools/#django.test.SimpleTestCase.databases
17
- databases = "__all__"
18
+ @ pytest . mark . django_db ( databases = list ( settings . DATABASES . keys ()))
19
+ class BaseDBTest :
20
+ pass
18
21
19
22
20
- @skipUnless (connections ["test_db_1" ].vendor == "sqlite" , "Skipped unless test_db_1 uses sqlite" )
21
- class TestDbMetrics (BaseDbMetricTest ):
23
+ @pytest . mark . skipif (connections ["test_db_1" ].vendor != "sqlite" , reason = "Skipped unless test_db_1 uses sqlite" )
24
+ class TestDbMetrics (BaseDBTest ):
22
25
"""Test django_prometheus.db metrics.
23
26
24
27
Note regarding the values of metrics: many tests interact with the
@@ -96,8 +99,8 @@ def test_execute_many(self):
96
99
)
97
100
98
101
99
- @skipUnless ("postgresql" in connections , "Skipped unless postgresql database is enabled" )
100
- class TestPostgresDbMetrics (BaseDbMetricTest ):
102
+ @pytest . mark . skipif ("postgresql" not in connections , reason = "Skipped unless postgresql database is enabled" )
103
+ class TestPostgresDbMetrics (BaseDBTest ):
101
104
"""Test django_prometheus.db metrics for postgres backend.
102
105
103
106
Note regarding the values of metrics: many tests interact with the
@@ -123,8 +126,8 @@ def test_counters(self):
123
126
)
124
127
125
128
126
- @skipUnless ("mysql" in connections , "Skipped unless mysql database is enabled" )
127
- class TestMysDbMetrics (BaseDbMetricTest ):
129
+ @pytest . mark . skipif ("mysql" not in connections , reason = "Skipped unless mysql database is enabled" )
130
+ class TestMysDbMetrics (BaseDBTest ):
128
131
"""Test django_prometheus.db metrics for mys backend.
129
132
130
133
Note regarding the values of metrics: many tests interact with the
@@ -150,8 +153,8 @@ def test_counters(self):
150
153
)
151
154
152
155
153
- @skipUnless ("postgis" in connections , "Skipped unless postgis database is enabled" )
154
- class TestPostgisDbMetrics (BaseDbMetricTest ):
156
+ @pytest . mark . skipif ("postgis" not in connections , reason = "Skipped unless postgis database is enabled" )
157
+ class TestPostgisDbMetrics (BaseDBTest ):
155
158
"""Test django_prometheus.db metrics for postgis backend.
156
159
157
160
Note regarding the values of metrics: many tests interact with the
0 commit comments