Equivalent of `post` in 2.0? (How to build artifacts from a failed test?)



Perhaps I’m missing something, but in 1.0, it was pretty easy to get a coverage report built as an artifact even if a test failed. For example, in python this snippet in circle.yml would collect coverage data while running tests with py.test. Even if the test failed, artifacts would be stored in output

    - coverage run --source mymodule -m py.test tests
    - coverage html -d output

In 2.0, using a similar snippet results in an exit right after failure in the first run, skipping the reporting step, and a failure during upload. I can fix this by combing tests and reporting and adding set +e but then the step isn’t properly marked as a failure

      - run:
          name: Run tests
          command: coverage run --source mymodule -m py.test tests
      - run:
          name: Report coverage
          command: coverage html -d output
      - store_artifacts:
          path: output
          destination: mymodule


At this time, you can’t run a command after one fails but artifacts will always upload. Someone did post a workaround on here to surface an error to solve the problem you’re seeing, so it’s worth a search, but we don’t natively support it yet.


Yes, I can combine into a single run and do something like this

coverage run --source mymodule -m py.test tests || FAILED="TRUE"
coverage html -d output
if [[ -z "$FAILED" ]] ; then
   exit 0;
   exit 1;

I find it surprising that the (to me, at least) basic functionality of post was not somehow retained in version 2.0. Fast failures are desirable, but so is some ability to clean up, at least in the way I use CI


Note: in this case another workaround is to use pytest-cov, which will write coverage reports and run tests in a single line:

 pytest --cov-report html:output --cov=mymodule tests/

but the bash trick above is still needed for the same effect as post


This is now available with the when directive;