Globbing Tests
To utilize test splitting with CircleCI we require that you pass in a list of tests to run. However, with how you execute tests with Django you are unable to simply glob the tests and pass them in.
Someone shared the issues they ran into, and a solution, in the following Discuss post:
Example
Using the above, here is a quick example of how to accomplish test splitting:
- run:
command: |
# get test files while ignoring __init__ files
TESTFILES=$(circleci tests glob "catalog/tests/*.py" | sed 's/\S\+__init__.py//g')
echo $TESTFILES | tr ' ' '\n' | sort | uniq > circleci_test_files.txt
cat circleci_test_files.txt
TESTFILES=$(circleci tests split --split-by=timings circleci_test_files.txt)
# massage filepaths into format manage.py test accepts
TESTFILES=$(echo $TESTFILES | tr "/" "." | sed 's/.py//g')
echo $TESTFILES
pipenv run python manage.py test --verbosity=2 $TESTFILES