Skip to content

Commit bea7696

Browse files
authored
More pytest migrations (DB tests) (#401)
* More pytest migrations (DB tests)
1 parent 764d67b commit bea7696

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

django_prometheus/tests/end2end/testapp/test_db.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
from unittest import skipUnless
2-
1+
import pytest
2+
from django.conf import settings
33
from django.db import connections
4-
from django.test import TestCase
54

65
from django_prometheus.testutils import (
76
assert_metric_compare,
@@ -11,14 +10,18 @@
1110
save_registry,
1211
)
1312

13+
# @pytest.fixture(autouse=True)
14+
# def enable_db_access_for_all_tests(db):
15+
# pass
16+
1417

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
1821

1922

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):
2225
"""Test django_prometheus.db metrics.
2326
2427
Note regarding the values of metrics: many tests interact with the
@@ -96,8 +99,8 @@ def test_execute_many(self):
9699
)
97100

98101

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):
101104
"""Test django_prometheus.db metrics for postgres backend.
102105
103106
Note regarding the values of metrics: many tests interact with the
@@ -123,8 +126,8 @@ def test_counters(self):
123126
)
124127

125128

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):
128131
"""Test django_prometheus.db metrics for mys backend.
129132
130133
Note regarding the values of metrics: many tests interact with the
@@ -150,8 +153,8 @@ def test_counters(self):
150153
)
151154

152155

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):
155158
"""Test django_prometheus.db metrics for postgis backend.
156159
157160
Note regarding the values of metrics: many tests interact with the

0 commit comments

Comments
 (0)