|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
3 | 3 | import pytest
|
| 4 | +import pytest_django |
4 | 5 | import json
|
5 | 6 |
|
6 | 7 | from werkzeug.test import Client
|
|
21 | 22 |
|
22 | 23 | from tests.integrations.django.myapp.wsgi import application
|
23 | 24 |
|
| 25 | +# Hack to prevent from experimental feature introduced in version `4.3.0` in `pytest-django` that |
| 26 | +# requires explicit database allow from failing the test |
| 27 | +pytest_mark_django_db_decorator = pytest.mark.django_db |
| 28 | +try: |
| 29 | + pytest_version = tuple(map(int, pytest_django.__version__.split("."))) |
| 30 | + if pytest_version > (4, 2, 0): |
| 31 | + pytest_mark_django_db_decorator = pytest.mark.django_db(databases="__all__") |
| 32 | +except ValueError: |
| 33 | + if "dev" in pytest_django.__version__: |
| 34 | + pytest_mark_django_db_decorator = pytest.mark.django_db(databases="__all__") |
| 35 | +except AttributeError: |
| 36 | + pass |
| 37 | + |
24 | 38 |
|
25 | 39 | @pytest.fixture
|
26 | 40 | def client():
|
@@ -245,7 +259,7 @@ def test_sql_queries(sentry_init, capture_events, with_integration):
|
245 | 259 |
|
246 | 260 |
|
247 | 261 | @pytest.mark.forked
|
248 |
| -@pytest.mark.django_db |
| 262 | +@pytest_mark_django_db_decorator |
249 | 263 | def test_sql_dict_query_params(sentry_init, capture_events):
|
250 | 264 | sentry_init(
|
251 | 265 | integrations=[DjangoIntegration()],
|
@@ -290,7 +304,7 @@ def test_sql_dict_query_params(sentry_init, capture_events):
|
290 | 304 | ],
|
291 | 305 | )
|
292 | 306 | @pytest.mark.forked
|
293 |
| -@pytest.mark.django_db |
| 307 | +@pytest_mark_django_db_decorator |
294 | 308 | def test_sql_psycopg2_string_composition(sentry_init, capture_events, query):
|
295 | 309 | sentry_init(
|
296 | 310 | integrations=[DjangoIntegration()],
|
@@ -323,7 +337,7 @@ def test_sql_psycopg2_string_composition(sentry_init, capture_events, query):
|
323 | 337 |
|
324 | 338 |
|
325 | 339 | @pytest.mark.forked
|
326 |
| -@pytest.mark.django_db |
| 340 | +@pytest_mark_django_db_decorator |
327 | 341 | def test_sql_psycopg2_placeholders(sentry_init, capture_events):
|
328 | 342 | sentry_init(
|
329 | 343 | integrations=[DjangoIntegration()],
|
|
0 commit comments