-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make is_django_unittest more straightforward
- Loading branch information
Showing
3 changed files
with
8 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters