Skip to content

More pytest migrations (DB tests) #401

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

Merged
merged 3 commits into from
May 9, 2023
Merged
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
31 changes: 17 additions & 14 deletions django_prometheus/tests/end2end/testapp/test_db.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import skipUnless

import pytest
from django.conf import settings
from django.db import connections
from django.test import TestCase

from django_prometheus.testutils import (
assert_metric_compare,
Expand All @@ -11,14 +10,18 @@
save_registry,
)

# @pytest.fixture(autouse=True)
# def enable_db_access_for_all_tests(db):
# pass


class BaseDbMetricTest(TestCase):
# https://docs.djangoproject.com/en/2.2/topics/testing/tools/#django.test.SimpleTestCase.databases
databases = "__all__"
@pytest.mark.django_db(databases=list(settings.DATABASES.keys()))
class BaseDBTest:
pass


@skipUnless(connections["test_db_1"].vendor == "sqlite", "Skipped unless test_db_1 uses sqlite")
class TestDbMetrics(BaseDbMetricTest):
@pytest.mark.skipif(connections["test_db_1"].vendor != "sqlite", reason="Skipped unless test_db_1 uses sqlite")
class TestDbMetrics(BaseDBTest):
"""Test django_prometheus.db metrics.

Note regarding the values of metrics: many tests interact with the
Expand Down Expand Up @@ -96,8 +99,8 @@ def test_execute_many(self):
)


@skipUnless("postgresql" in connections, "Skipped unless postgresql database is enabled")
class TestPostgresDbMetrics(BaseDbMetricTest):
@pytest.mark.skipif("postgresql" not in connections, reason="Skipped unless postgresql database is enabled")
class TestPostgresDbMetrics(BaseDBTest):
"""Test django_prometheus.db metrics for postgres backend.

Note regarding the values of metrics: many tests interact with the
Expand All @@ -123,8 +126,8 @@ def test_counters(self):
)


@skipUnless("mysql" in connections, "Skipped unless mysql database is enabled")
class TestMysDbMetrics(BaseDbMetricTest):
@pytest.mark.skipif("mysql" not in connections, reason="Skipped unless mysql database is enabled")
class TestMysDbMetrics(BaseDBTest):
"""Test django_prometheus.db metrics for mys backend.

Note regarding the values of metrics: many tests interact with the
Expand All @@ -150,8 +153,8 @@ def test_counters(self):
)


@skipUnless("postgis" in connections, "Skipped unless postgis database is enabled")
class TestPostgisDbMetrics(BaseDbMetricTest):
@pytest.mark.skipif("postgis" not in connections, reason="Skipped unless postgis database is enabled")
class TestPostgisDbMetrics(BaseDBTest):
"""Test django_prometheus.db metrics for postgis backend.

Note regarding the values of metrics: many tests interact with the
Expand Down