Skip to content

Instantly share code, notes, and snippets.

@mikeengland
Last active December 23, 2016 01:15
Show Gist options
  • Save mikeengland/1ae5c3978a15e155a1412f0ef24bf924 to your computer and use it in GitHub Desktop.
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>`
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