From 21601561a6ff8d858a7c740b559df70b1483c739 Mon Sep 17 00:00:00 2001 From: Ben Farley <47006790+farleyb-amazon@users.noreply.github.com> Date: Fri, 26 Mar 2021 11:13:47 -0600 Subject: [PATCH] chore: Fail build if code coverage is too low (#153) --- buildspec.yml | 3 +++ codebuild/coverage/coverage.yml | 14 ++++++++++++++ setup.cfg | 1 + tox.ini | 10 +++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 codebuild/coverage/coverage.yml diff --git a/buildspec.yml b/buildspec.yml index 7bef08e4..02307f95 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -13,3 +13,6 @@ batch: buildspec: codebuild/python3.7.yml - identifier: python3_8 buildspec: codebuild/python3.8.yml + + - identifier: code_coverage + buildspec: codebuild/coverage/coverage.yml diff --git a/codebuild/coverage/coverage.yml b/codebuild/coverage/coverage.yml new file mode 100644 index 00000000..f82a3a98 --- /dev/null +++ b/codebuild/coverage/coverage.yml @@ -0,0 +1,14 @@ +version: 0.2 + +env: + variables: + TOXENV: "coverage" + +phases: + install: + runtime-versions: + python: latest + build: + commands: + - pip install tox + - tox diff --git a/setup.cfg b/setup.cfg index a4080d60..0b64cb5c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -9,6 +9,7 @@ branch = True [coverage:report] show_missing = True +fail_under = 90 [mypy] ignore_missing_imports = True diff --git a/tox.ini b/tox.ini index 33f1aff9..fae478e3 100644 --- a/tox.ini +++ b/tox.ini @@ -35,8 +35,12 @@ envlist = # test-release :: Builds dist files and uploads to testpypi pypirc profile. # release :: Builds dist files and uploads to pypi pypirc profile. +# Reporting environments: +# +# coverage :: Runs code coverage, failing the build if coverage is below the configured threshold + [testenv:base-command] -commands = pytest --basetemp={envtmpdir} -l --cov dynamodb_encryption_sdk {posargs} +commands = pytest --basetemp={envtmpdir} -l {posargs} [testenv] passenv = @@ -86,6 +90,10 @@ commands = # Only run examples tests examples: {[testenv:base-command]commands} examples/test/ -m "examples" +# Run code coverage on the unit tests +[testenv:coverage] +commands = {[testenv:base-command]commands} --cov dynamodb_encryption_sdk test/ -m "local and not slow and not veryslow and not nope" + # Verify that local tests work without environment variables present [testenv:nocmk] basepython = python3