Skip to content

Instantly share code, notes, and snippets.

@datagrok
datagrok / gist:2199506
Last active April 8, 2023 17:36
Virtualenv's `bin/activate` is Doing It Wrong
@turicas
turicas / virtualenv_execute.py
Created June 8, 2012 19:23
Execute Python code in a virtualenv, return its stdout and stderr
#!/usr/bin/env python
# coding: utf-8
import os
import shlex
from subprocess import Popen, PIPE
def execute_in_virtualenv(virtualenv_name, commands):
'''Execute Python code in a virtualenv, return its stdout and stderr.'''
@mikeengland
mikeengland / django_parallel_tests.py
Last active December 23, 2016 01:15
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')