DEV Community

Reece Dunham
Reece Dunham

Posted on • Updated on

Setting up Python unittests with GitHub annotations

This is my first post on DEV, so I'm going to try to make this quick and simple.

If you want inline examples of exactly where your code is failing, you can integrate Cirrus CI with GitHub annotations. This is super simple to do.

  1. Start off by writing unittests. This is super simple.
  2. Setup a basic CI pipeline (.cirrus.yml file). You will want to do something like this:
  # define Docker container
    image: python:latest

  # install project requirements and the annotation result builder
  install_script: |
    pip install -r ./some-requirements-file.txt
    pip install unittest-xml-reporting

  # normally, you would run unittests with the main command
  # we need to build XML reports, so use this command
  script: python3 -m xmlrunner tests
  # replace tests with the name of the module your unittests are in

  # (always) upload results - even if the tests fail
      # where the outputted XML files are
      path: ./*.xml
      # required, even though it sounds wrong
      format: junit
Enter fullscreen mode Exit fullscreen mode

And that is all you need to do!
You should then get annotations.

Have a nice day!

Top comments (0)