简体   繁体   中英

How do I enforce a minimum test coverage percentage in my Foundry Code Repositories?

I not only want to write unit tests in my Foundry Code Repository, but I want to enforce a minimum amount of coverage for checks to pass.

It's a best practice to ensure that I'm covering at least a certain fraction of my code with unit tests, but tests don't seem to be a requirement in standard repositories.

How do I accomplish my two testing goals within my Foundry Code Repository?

You can use PyTest Coverage to compute coverage and enforce a minimum percentage.

  1. Add the following to your repo's meta.yml :
...

test:
  requires:
    - pytest-cov
...

Note: this is outside the requirements section in a section of its own.

  1. Create a pytest.ini file at /transforms-python/src/pytest.ini with the following contents:
[pytest]
addopts = --cov=<<package name, e.g. myproject>> --cov-report term --cov-fail-under=100

Note: you can tune the enforcement percentage down from 100 if you'd like

Your tests will now fail, even if they include some unit tests, if that coverage threshold is below your configured value:

检查

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM