Skip to content

Commit

Permalink
Make is_django_unittest more straightforward
Browse files Browse the repository at this point in the history
  • Loading branch information
pelme committed Jan 2, 2015
1 parent 83d53f6 commit fa18604
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
17 changes: 6 additions & 11 deletions pytest_django/django_compat.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
# Note that all functions here assume django is available. So ensure
# this is the case before you call them.
import sys


def is_django_unittest(item):
"""Returns True if the item is a Django test case, otherwise False"""
def is_django_unittest(request_or_item):
"""Returns True if the request_or_item is a Django test case, otherwise False"""
try:
from django.test import SimpleTestCase as TestCase
except ImportError:
from django.test import TestCase

if not hasattr(item, 'obj'):
return False
cls = getattr(request_or_item, 'cls', None)

if sys.version_info < (3, 0):
return (hasattr(item.obj, 'im_class') and
issubclass(item.obj.im_class, TestCase))
if cls is None:
return False

return (hasattr(item.obj, '__self__') and
hasattr(item.obj.__self__, '__class__') and
issubclass(item.obj.__self__.__class__, TestCase))
return issubclass(cls, TestCase)
2 changes: 1 addition & 1 deletion pytest_django/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def teardown_database():


def _django_db_fixture_helper(transactional, request, _django_cursor_wrapper):
if is_django_unittest(request.node):
if is_django_unittest(request):
return

if transactional:
Expand Down
2 changes: 1 addition & 1 deletion pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def _django_db_marker(request):
@pytest.fixture(autouse=True)
def _django_setup_unittest(request, _django_cursor_wrapper):
"""Setup a django unittest, internal to pytest-django"""
if django_settings_is_configured() and is_django_unittest(request.node):
if django_settings_is_configured() and is_django_unittest(request):
request.getfuncargvalue('_django_test_environment')
request.getfuncargvalue('_django_db_setup')
_django_cursor_wrapper.enable()
Expand Down

0 comments on commit fa18604

Please sign in to comment.