Skip to content

Instantly share code, notes, and snippets.

@jdunck
Last active January 19, 2018 16:16
Show Gist options
  • Save jdunck/f9da77aab4a49838772d to your computer and use it in GitHub Desktop.
Save jdunck/f9da77aab4a49838772d to your computer and use it in GitHub Desktop.
py.test parallel execution for CircleCI
test:
override:
- find . -maxdepth 1 -type d -not -name . > test_dirs:
parallel: true
- python circle_node_to_dirs.py < test_dirs > test_dirs_for_node:
parallel: true
- echo "Testing `cat test_dirs_for_node`":
parallel: true
- py.test `cat test_dirs_for_node`:
parallel: true
import os, sys, itertools
def test_dir_portion(node_index, node_total, test_dirs):
for_node = [v for _, v in filter(lambda (index, test_dir): (index % node_total) == node_index, enumerate(test_dirs))]
return for_node
def main():
node_index = int(os.environ.get('CIRCLE_NODE_INDEX', 1))
node_total = int(os.environ.get('CIRCLE_NODE_TOTAL', 1))
test_dirs = filter(str, sys.stdin.read().split('\n'))
test_dirs_for_node = test_dir_portion(node_index, node_total, test_dirs)
print " ".join(test_dirs_for_node)
if __name__ == '__main__':
main()
@jdunck
Copy link
Author

jdunck commented Nov 12, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment