DEV Community

Reece Dunham
Reece Dunham

Posted on • Edited on

3

Setting up Python unittests with GitHub annotations

Hello!
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:
tests_task:
  # define Docker container
  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
  always:
    unittest_results_artifacts:
      # 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!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay