Skip to content

Commit 5efd59f

Browse files
authored
Allowing to skip tests with 'SuppressMessageAttribute' (#178)
* Allowing to skip tests with 'SuppressMessageAttribute' * Add documentation for skipping SuppressMessageAttribute tests * Fix changelog section header
1 parent 909ea07 commit 5efd59f

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Added tag `AllowSuppressMessageAttribute` to test `Should not suppress the required rule` to allow usage of `SuppressMessageAttribute` [#135](https://github.com/dsccommunity/DscResource.Test/issues/135).
13+
1014
## [0.19.0] - 2026-01-23
1115

1216
### Fixed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,6 +1174,37 @@ Invoke-Pester -Container $container -Output Detailed
11741174

11751175
### PSSAResource.common
11761176

1177+
This test runs PSScriptAnalyzer against the source files and validates
1178+
compliance with required and custom rules.
1179+
1180+
#### Skipping tests that validate SuppressMessageAttribute usage
1181+
1182+
The test `Should not suppress the required rule` validates that no required
1183+
PSSA rules are suppressed using `SuppressMessageAttribute`. If you need to
1184+
suppress a required rule in your module (which is generally not recommended),
1185+
you can exclude this specific test by using the tag `AllowSuppressMessageAttribute`
1186+
with the `ExcludeTagFilter` parameter.
1187+
1188+
**Example using build.yaml:**
1189+
1190+
```yaml
1191+
DscTest:
1192+
Pester:
1193+
ExcludeTagFilter:
1194+
- AllowSuppressMessageAttribute
1195+
```
1196+
1197+
**Example using Invoke-Pester directly:**
1198+
1199+
```powershell
1200+
$container = New-PesterContainer -Path "$pathToHQRMTests/PSSAResource.common.*.Tests.ps1" -Data @{
1201+
ProjectPath = '.'
1202+
ModuleBase = "./output/$dscResourceModuleName/*"
1203+
}
1204+
1205+
Invoke-Pester -Container $container -ExcludeTagFilter 'AllowSuppressMessageAttribute'
1206+
```
1207+
11771208
#### Parameters
11781209

11791210
<!-- markdownlint-disable MD013 - Line length -->

source/Tests/QA/PSSAResource.common.v5.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Describe 'Common Tests - PS Script Analyzer on Source Files' -Tag @('DscPSSA', '
166166
}
167167
}
168168

169-
It 'Should not suppress the required rule ''<_>''' -ForEach $requiredRuleToTest -Tag @('Common Tests - Required Script Analyzer Rules', 'RequiredPSSA') {
169+
It 'Should not suppress the required rule ''<_>''' -ForEach $requiredRuleToTest -Tag @('Common Tests - Required Script Analyzer Rules', 'RequiredPSSA', 'AllowSuppressMessageAttribute') {
170170
$_ | Should -Not -BeIn $suppressedRuleNames -Because 'no module script file should suppress a required Script Analyzer rule'
171171
}
172172

0 commit comments

Comments
 (0)