From da423483586fd795ccbdc168f647a00b5e10480d Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 10 Aug 2026 12:01:19 -0400 Subject: [PATCH] ci: exclude test code from SonarCloud duplication detection (#1207) (#1213) Duplication is scored on new code only, so a PR adding cases to an already repetitive test module inherits debt accrued across earlier PRs rather than introducing it; tests/unit/modules/test_module_helm.py sits at 47.9% on main before any change. sonar.exclusions filters the source set, not the copy/paste detector, so test code needs its own exclusion. Production code stays covered. (cherry picked from commit f31ecce59c259135767bed5c661c749d476970d4) Co-authored-by: Yuriy Novostavskiy --- sonar-project.properties | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sonar-project.properties b/sonar-project.properties index 08daeb53..53b20ab7 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -13,6 +13,17 @@ sonar.newCode.referenceBranch=stable-6 sonar.exclusions=tests/**,.tox/** +# Exclude test code from copy/paste detection. 'sonar.exclusions' above only +# filters the *source* set (it disambiguates 'sonar.sources=.' from +# 'sonar.tests'), so test files are still indexed as tests and still scored for +# duplication. Unit tests here are unittest.TestCase classes: every class needs +# its own setUp, and per-case arrange/assert blocks are deliberately repeated so +# a failing test reads on its own. Because SonarCloud scores only *new code* on +# a pull request, any PR adding cases to an already-repetitive test module +# inherits duplication accrued across earlier PRs. Production code under +# plugins/ stays fully covered by duplication analysis. +sonar.cpd.exclusions=tests/** + # Ansible module argument_spec is conventionally defined with the dict(...) # constructor (not {...} literals) for readability and consistency across the # collection. Suppress python:S7498 ("prefer literal syntax"), which conflicts