Skip to main content

Linting and coverage reports for diff only

Project description

Diff cov lint

Linting and coverage reports for git diff only.


diff-cov-lint master new_branch --cov_report=coverage.xml --lint_report=pylint_output.txt

Example output (the command above was run in tests/repo folder):

======================== DIFF COVERAGE ========================
FILE                                    COVERED STMTS   PERCENT
src/                                    5     8     62.5%
src/                                 1     2     50.0%
TOTAL DIFF COV                                6    10     60.0%

========================== DIFF LINT ==========================
src/ E0602: Undefined variable 'this_line_makes_no_sense' (undefined-variable)


TARGET_REF Target branch in repo
SOURCE_REF Source branch in repo

Path to coverage report in Cobertura (pytest-cov) format, If not stated, coverage report will not be produced.
Path to pylint report. If not stated, linting report will not be produced.
Path to repo folder, defaults to "."

CI Setup

This project's repo uses diff-cov-lint itself. You might want to check .gitlab-ci.yml for full configuration.

The scenario is following:

  • Run tests on each push (test job)
  • Calculate diff coverage and produce diff pylint reports for merge requests (code_quality_diff job)
  • Get coverage and pylint report on full code on master and tags or manually on any push. (code_quality_full job)

Test job:

    stage: test
        - pytest --cov=your_source_folder --cov-report xml tests # run pytest and produce xml report
            - coverage.xml # save xml report to use it in further jobs
        - tags  # tags and branches are default values of "only", so preserve them
        - branches
        - merge_requests # add merge_requests since code_quality_diff job will use artifacts of this job

Diff code quality job:

    stage: code_quality_diff
        - git fetch -a # fetch all branches to calculate diff
        - pip install diff-cov-lint # install diff-cov-lint
        - pylint --exit-zero diff_cov_lint > pylint_output.txt # get pylint report. --exit-zero needed for job not to fail if pylint give score less than 10.
        - diff-cov-lint origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME origin/$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME --cov_report coverage.xml --lint_report pylint_output.txt # run diff-cov-lint on diff between target branch and source branch. coverage.xml is used from the artifact.
        - merge_requests

Full code quality job:

        - pytest --cov=your_source_folder tests # simply run pytest with coverage and pylint as usual
        - pylint --exit-zero diff_cov_lint
        - if: '$CI_COMMIT_REF_NAME == "master"'
        - if: $CI_MERGE_REQUEST_ID
          when: never #otherwise this job will stuck for merge requests
        - when: manual # use manual to make this job optional. 

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for diff-cov-lint, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size diff_cov_lint-0.1.1-py3-none-any.whl (7.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size diff_cov_lint-0.1.1.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page