OpenSlides/tests/conftest.py
Oskar Hahn 10b3bb6497 Update to channels 2
* geis does not work with channels2 and never will be (it has to be python now)
* pytest
* rewrote cache system
* use username instead of pk for admin user in tests
2018-08-22 06:30:11 +02:00

41 lines
1.3 KiB
Python

from django.test import TestCase, TransactionTestCase
from pytest_django.plugin import validate_django_db
def pytest_collection_modifyitems(items):
"""
Helper until https://github.com/pytest-dev/pytest-django/issues/214 is fixed.
"""
def get_marker_transaction(test):
marker = test.get_marker('django_db')
if marker:
validate_django_db(marker)
return marker.kwargs['transaction']
return None
def has_fixture(test, fixture):
funcargnames = getattr(test, 'funcargnames', None)
return funcargnames and fixture in funcargnames
def weight_test_case(test):
"""
Key function for ordering test cases like the Django test runner.
"""
is_test_case_subclass = test.cls and issubclass(test.cls, TestCase)
is_transaction_test_case_subclass = test.cls and issubclass(test.cls, TransactionTestCase)
if is_test_case_subclass or get_marker_transaction(test) is False:
return 0
elif has_fixture(test, 'db'):
return 0
if is_transaction_test_case_subclass or get_marker_transaction(test) is True:
return 1
elif has_fixture(test, 'transactional_db'):
return 1
return 0
items.sort(key=weight_test_case)