Use test splitting with Python Django 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:

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\')
      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 test accepts
      TESTFILES=$(echo $TESTFILES | tr "/" "." | sed 's/.py//g')
      echo $TESTFILES
      pipenv run python test --verbosity=2 $TESTFILES  
Was this article helpful?
1 out of 1 found this helpful



Article is closed for comments.