Last active
January 19, 2018 16:16
-
-
Save jdunck/f9da77aab4a49838772d to your computer and use it in GitHub Desktop.
py.test parallel execution for CircleCI
This file contains 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
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 |
This file contains 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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also: https://github.com/jdunck/pytest-circleci/tree/stable-removal