Skip to content

Instantly share code, notes, and snippets.

@nicoddemus
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicoddemus/58db6fabefdc43652c57 to your computer and use it in GitHub Desktop.
Save nicoddemus/58db6fabefdc43652c57 to your computer and use it in GitHub Desktop.
Rename all tests from "pytest_" to "test_", including data directories
import os
import fnmatch
import sys
directory = sys.argv[1]
for root, dirs, names in os.walk(sys.argv[1]):
for name in names:
if fnmatch.fnmatch(name, 'pytest_*.py') and os.path.basename(root) == '_tests':
source = os.path.join(root, name)
target = os.path.join(root, name[2:])
if not os.path.isfile(target):
data_dir = os.path.splitext(source)[0]
if os.path.isdir(data_dir):
dir_name = os.path.basename(data_dir)[2:]
target_dir = os.path.join(os.path.dirname(data_dir), dir_name)
os.rename(data_dir, target_dir)
subprocess.call('git mv %s %s' % (source, target))
else:
print '***', target, 'already exists: merge the two tests'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment