Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Python coverage.pl report for Gitlab

I'm new to Gitlab, trying to setup coverage report -m for Gitlab. When I run manually, coverage report -m gives me the report. Just cant figure out what needs to be done to get that display on Gitlab.

This needs to run with Python 3.6 unit test code coverage on Linux for Gitlab.

Here is my yml file

stages: 
- build 
- test 
- coverage
- deploy

before_script:
  - python --version
  - pip install -r requirements.txt
  
unit-tests:  
 image:    
  name: "python:3.6" 
  entrypoint: [""]  
 stage: test  
 script: python3 -m unittest discover

test:
 image:   
  name: "python:3.6"
 stage: test
 script: 
   - PYTHONPATH=$(pwd) python3 my_Project_Lib/my_test_scripts/runner.py

coverage:
  stage: test
  script:
      #- docker pull $CONTAINER_TEST_IMAGE
      - python3 -m unittest discover
      #- docker run $CONTAINER_TEST_IMAGE /bin/bash -c "python -m coverage run tests/tests.py && python -m coverage report -m"
      
  coverage: '/TOTAL.+ ([0-9]{1,3}%)/'

This runs my unit tests and runer.pl fine, but no test coverage data.

like image 834
dnrp Avatar asked Jan 26 '23 04:01

dnrp


1 Answers

Below is a working solution for Unit Test Code coverage.

Here is my .yml-file

stages: 
- build 
- test 
- coverage
- deploy

before_script:
  - pip install -r requirements.txt

test:
 image:   
  name: "python:3.6"
 stage: test
 script: 
   - python my_Project_Lib/my_test_scripts/runner.py

unit-tests:
  stage: test
  script:
      - python -m unittest discover
      - coverage report -m
      - coverage-badge
      
  coverage: '/TOTAL.+ ([0-9]{1,3}%)/'

This runs my unit tests and runner.py fine, also runs coverage. You will need following in requirements.txt

coverage
coverage-badge

Also this line in README.MD

[![coverage report](https://gitlab.your_link.com/your_user_name/your directory/badges/master/coverage.svg)](https://gitlab.your_link.com/your_user_name/your directory/commits/master)

Your user name and link can be copied from web address.

like image 137
dnrp Avatar answered Jan 29 '23 07:01

dnrp