Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions tests/integrations/django/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import

import pytest
import pytest_django
import json

from werkzeug.test import Client
Expand All @@ -21,6 +22,19 @@

from tests.integrations.django.myapp.wsgi import application

# Hack to prevent from experimental feature introduced in version `4.3.0` in `pytest-django` that
# requires explicit database allow from failing the test
pytest_mark_django_db_decorator = pytest.mark.django_db
try:
pytest_version = tuple(map(int, pytest_django.__version__.split(".")))
if pytest_version > (4, 2, 0):
pytest_mark_django_db_decorator = pytest.mark.django_db(databases="__all__")
except ValueError:
if "dev" in pytest_django.__version__:
pytest_mark_django_db_decorator = pytest.mark.django_db(databases="__all__")
except AttributeError:
pass
Comment on lines +27 to +36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is simpler:

Suggested change
pytest_mark_django_db_decorator = pytest.mark.django_db
try:
pytest_version = tuple(map(int, pytest_django.__version__.split(".")))
if pytest_version > (4, 2, 0):
pytest_mark_django_db_decorator = pytest.mark.django_db(databases="__all__")
except ValueError:
if "dev" in pytest_django.__version__:
pytest_mark_django_db_decorator = pytest.mark.django_db(databases="__all__")
except AttributeError:
pass
pytest_mark_django_db_decorator = pytest.mark.django_db(databases="__all__")
try:
pytest_version = tuple(map(int, pytest_django.__version__.split(".")))
if pytest_version <= (4, 2, 0):
pytest_mark_django_db_decorator = pytest.mark.django_db
except (ValueError, AttributeError):
pass

you'd have to test if this works though

@ahmedetefy ahmedetefy Jun 1, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah that would not work because pytest_django.__version__ was introduced in 4.0 I think, which means it will default to pytest.mark.django_db(databases="__all__") which isn't great because that will fail the tests for pytest_django versions <4.3

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



@pytest.fixture
def client():
Expand Down Expand Up @@ -245,7 +259,7 @@ def test_sql_queries(sentry_init, capture_events, with_integration):


@pytest.mark.forked
@pytest.mark.django_db
@pytest_mark_django_db_decorator
def test_sql_dict_query_params(sentry_init, capture_events):
sentry_init(
integrations=[DjangoIntegration()],
Expand Down Expand Up @@ -290,7 +304,7 @@ def test_sql_dict_query_params(sentry_init, capture_events):
],
)
@pytest.mark.forked
@pytest.mark.django_db
@pytest_mark_django_db_decorator
def test_sql_psycopg2_string_composition(sentry_init, capture_events, query):
sentry_init(
integrations=[DjangoIntegration()],
Expand Down Expand Up @@ -323,7 +337,7 @@ def test_sql_psycopg2_string_composition(sentry_init, capture_events, query):


@pytest.mark.forked
@pytest.mark.django_db
@pytest_mark_django_db_decorator
def test_sql_psycopg2_placeholders(sentry_init, capture_events):
sentry_init(
integrations=[DjangoIntegration()],
Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ deps =
django-{1.6,1.7}: pytest-django<3.0
django-{1.8,1.9,1.10,1.11,2.0,2.1}: pytest-django<4.0
django-{2.2,3.0,3.1}: pytest-django>=4.0
django-{2.2,3.0,3.1}: Werkzeug<2.0
django-dev: git+https://github.com/pytest-dev/pytest-django#egg=pytest-django

django-1.6: Django>=1.6,<1.7
Expand Down Expand Up @@ -201,7 +202,7 @@ deps =
trytond-5.0: trytond>=5.0,<5.1
trytond-4.6: trytond>=4.6,<4.7

trytond-4.8: werkzeug<1.0
trytond-{4.6,4.8,5.0,5.2,5.4}: werkzeug<2.0

redis: fakeredis

Expand Down Expand Up @@ -297,9 +298,7 @@ commands =

; https://github.com/pytest-dev/pytest/issues/5532
{py3.5,py3.6,py3.7,py3.8,py3.9}-flask-{0.10,0.11,0.12}: pip install pytest<5

; trytond tries to import werkzeug.contrib
trytond-5.0: pip install werkzeug<1.0
{py3.6,py3.7,py3.8,py3.9}-flask-{0.11}: pip install Werkzeug<2

py.test {env:TESTPATH} {posargs}

Expand Down