Last active
December 23, 2016 01:15
-
-
Save mikeengland/1ae5c3978a15e155a1412f0ef24bf924 to your computer and use it in GitHub Desktop.
Overrides the default test database name so that multiple instances of Django parallel tests using the same database instance do not clash e.g. when testing multiple branches at once (like Bamboo's plan branches). Run using: `python manage.py test --testrunner='<path>.<to>.<class>.ParallelTestRunner' --parallel=<num_parallel_processes>`
This file contains hidden or 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
from datetime import datetime | |
from django.test.runner import DiscoverRunner | |
class ParallelTestRunner(DiscoverRunner): | |
""" | |
Uses a combination of hours, minutes and microseconds. This should avoid any db name conflicts and when | |
Django creates the db, the name will abide by the MySQL 16 character limit. | |
""" | |
settings.DATABASES[DEFAULT_DB_ALIAS]['NAME'] = datetime.utcnow().strftime('%H%M%f') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment