You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Discovery of tests in any test module¶
Django 1.6 ships with a new test runner that allows more flexibility in the location of tests. The previous runner (django.test.simple.DjangoTestSuiteRunner) found tests only in the models.py and tests.py modules of a Python package in INSTALLED_APPS.
The new runner (django.test.runner.DiscoverRunner) uses the test discovery features built into unittest2 (the version of unittest in the Python 2.7+ standard library, and bundled with Django). With test discovery, tests can be located in any module whose name matches the pattern test*.py.
The text was updated successfully, but these errors were encountered:
Also, pymongo uses now MongoClient instead of Connection, and you need to disconnect from default database
A quick fix may be:
from django.test.runner import DiscoverRunner
from django.test import TransactionTestCase
from django.conf import settings
from mongoengine import connect, disconnect
from pymongo import MongoClient
class TestRunner(DiscoverRunner):
"""
Custom test runner for mongoengine
"""
def setup_databases(self, **kwargs):
db_name = settings.TEST_DBNAME # test db defined on settings
disconnect() # disconnect from default db
connect(db_name)
print 'Connecting to test database: ' + db_name
return db_name
def teardown_databases(self, db_name, **kwargs):
if not self.keepdb:
conn = MongoClient()
conn.drop_database(db_name)
print 'Dropping test database: ' + db_name
class TestCase(TransactionTestCase):
def _fixture_setup(self):
pass
This code won't work in Django 1.8 since it removes django.test.simple.
From https://docs.djangoproject.com/en/1.8/releases/1.6/#discovery-of-tests-in-any-test-module:
The text was updated successfully, but these errors were encountered: