You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PSModule framework tests run automatically as part of the `Test-Module` and `Test-SourceCode` jobs. While you can skip entire test categories using the configuration settings (e.g., `Test.PSModule.Skip`), you can also skip individual framework tests on a per-file basis when needed.
451
+
452
+
### How to Skip Tests
453
+
454
+
To skip an individual framework test for a specific file, add a special comment at the top of that file:
455
+
456
+
```powershell
457
+
#SkipTest:<TestID>:<Reason>
458
+
```
459
+
460
+
- `<TestID>`: The unique identifier of the test to skip (see list below)
461
+
- `<Reason>`: A brief explanation of why the test is being skipped
462
+
463
+
The skip comment will cause the framework to skip that specific test for that file only, and will log a warning in the build output with the reason provided.
464
+
465
+
### Available Framework Tests
466
+
467
+
#### SourceCode Tests
468
+
469
+
These tests run against your source code files in the `src` directory:
470
+
471
+
| Test ID | Description | Example Skip Comment |
472
+
|---------|-------------|---------------------|
473
+
| `NumberOfProcessors` | Enforces use of `[System.Environment]::ProcessorCount` instead of `$env:NUMBER_OF_PROCESSORS` | `#SkipTest:NumberOfProcessors:Legacy code compatibility required` |
474
+
| `Verbose` | Ensures `-Verbose` is not used unless explicitly disabled with `:$false` | `#SkipTest:Verbose:Required for debugging output` |
475
+
| `OutNull` | Enforces use of `$null = ...` instead of `... \| Out-Null` for better performance | `#SkipTest:OutNull:Pipeline output needed for compatibility` |
476
+
| `NoTernary` | Checks for ternary operators (currently skipped by default for PowerShell 7+ compatibility) | `#SkipTest:NoTernary:PowerShell 7+ only module` |
477
+
| `LowercaseKeywords` | Ensures all PowerShell keywords are lowercase | `#SkipTest:LowercaseKeywords:Generated code` |
478
+
| `FunctionCount` | Ensures each file contains exactly one function | `#SkipTest:FunctionCount:Helper functions included` |
479
+
| `FunctionName` | Ensures the filename matches the function name | `#SkipTest:FunctionName:Legacy naming convention` |
480
+
| `CmdletBinding` | Requires all functions to have `[CmdletBinding()]` attribute | `#SkipTest:CmdletBinding:Simple helper function` |
481
+
| `ParamBlock` | Requires all functions to have a `param()` block | `#SkipTest:ParamBlock:No parameters needed` |
482
+
| `FunctionTest` | Ensures all public functions have corresponding tests | `#SkipTest:FunctionTest:Test in development` |
483
+
484
+
#### Module Tests
485
+
486
+
These tests run against the compiled module in the `outputs/module` directory:
487
+
488
+
- Module import validation
489
+
- Module manifest validation
490
+
491
+
Module tests typically don't need to be skipped as they validate the final built module.
492
+
493
+
### Example Usage
494
+
495
+
Here's an example of a function file that skips the `FunctionCount` test because it includes helper functions:
496
+
497
+
```powershell
498
+
#SkipTest:FunctionCount:This file contains helper functions for the main function
499
+
500
+
function Get-ComplexData {
501
+
<#
502
+
.SYNOPSIS
503
+
Retrieves complex data using helper functions.
504
+
#>
505
+
[CmdletBinding()]
506
+
param(
507
+
[Parameter(Mandatory)]
508
+
[string] $Path
509
+
)
510
+
511
+
$data = Get-RawData -Path $Path
512
+
$processed = Format-ComplexData -Data $data
513
+
return $processed
514
+
}
515
+
516
+
function Get-RawData {
517
+
param([string]$Path)
518
+
# Helper function implementation
519
+
}
520
+
521
+
function Format-ComplexData {
522
+
param($Data)
523
+
# Helper function implementation
524
+
}
525
+
```
526
+
527
+
### Best Practices
528
+
529
+
- **Use skip comments sparingly**: Framework tests exist to maintain code quality and consistency. Only skip tests when absolutely necessary.
530
+
- **Provide clear reasons**: Always include a meaningful explanation in the skip comment to help reviewers understand why the test is being skipped.
531
+
- **Consider alternatives**: Before skipping a test, consider whether refactoring the code to comply with the test would be better for long-term maintainability.
532
+
- **Document exceptions**: If you skip a test, document the reason in your PR description or code comments.
533
+
534
+
### Related Configuration
535
+
536
+
For broader test control, use the configuration file settings:
537
+
538
+
- Skip all framework tests: `Test.PSModule.Skip: true`
539
+
- Skip only source code tests: `Test.SourceCode.Skip: true`
540
+
- Skip framework tests on specific OS: `Test.PSModule.Windows.Skip: true`
541
+
542
+
See the [Configuration](#configuration) section for more details.
0 commit comments