Tags
The tag parameter is now available on Describe, Context and It and it is possible to filter tags on any level. You can then use -TagFilter and -ExcludeTagFilter to run just the tests that you want.
Set Output.ShowTags to print the tags next to each Describe, Context and It in the console output, so you can see what your filter is actually matching.
Here you can see an example of a test suite that has acceptance tests and unit tests. Some of the tests are slow, some are flaky, and some only work on Linux. Pester makes running all reliable Windows-compatible acceptance tests as simple as:
Invoke-Pester $path -TagFilter "Acceptance" -ExcludeTagFilter "Flaky", "Slow", "LinuxOnly"
Describe "Get-Beer" {
Context "acceptance tests" -Tag "Acceptance" {
It "acceptance test 1" -Tag "Slow", "Flaky" {
1 | Should-Be 1
}
It "acceptance test 2" {
1 | Should-Be 1
}
It "acceptance test 3" -Tag "WindowsOnly" {
1 | Should-Be 1
}
It "acceptance test 4" -Tag "Slow" {
1 | Should-Be 1
}
It "acceptance test 5" -Tag "LinuxOnly" {
1 | Should-Be 1
}
}
Context "unit tests" {
It "unit test 1" {
1 | Should-Be 1
}
It "unit test 2" -Tag "LinuxOnly" {
1 | Should-Be 1
}
}
}
# Output level: Detailed
Running tests from 1 files.
Filter 'Tag' set to ('Acceptance').
Filter 'ExcludeTag' set to ('Flaky', 'Slow', 'LinuxOnly').
Filters selected 2 tests to run.
Running tests from '...\real-life-tagging-scenarios.tests.ps1'
Describing Get-Beer
Context acceptance tests
[+] acceptance test 2 50ms
[+] acceptance test 3 42ms
Tests completed in 1.09s
Tests Passed: 2, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 5
Tags use wildcards
The tags are now also compared as -like wildcards, so you don't have to spell out the whole tag if you can't remember it. This is especially useful when you are running tests locally:
Invoke-Pester $path -ExcludeTagFilter "Accept*", "*nuxonly" | Out-Null
# Output level: Detailed
Running tests from 1 files.
Filter 'ExcludeTag' set to ('Accept*', '*nuxonly').
Filters selected 1 tests to run.
Running tests from '...\real-life-tagging-scenarios.tests.ps1'
Describing Get-Beer
Context unit tests
[+] unit test 1 15ms
Tests completed in 269ms
Tests Passed: 1, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 6
Run tests that have no tags
Use the reserved tag None to select the tests that have no tags at all. -TagFilter "None" runs only the tests that have no tag on themselves or on any of their parent blocks, and -ExcludeTagFilter "None" does the opposite and skips them, so you run only the tagged tests. None is matched case-insensitively.
Because tags are inherited, a test without its own tag that sits inside a tagged Describe or Context counts as tagged and is not selected by None. In the suite above, acceptance test 2 has no tag of its own, but it lives in a Context tagged Acceptance, so -TagFilter "None" skips it and runs only the genuinely untagged unit test 1:
Invoke-Pester $path -TagFilter "None" | Out-Null
# Output level: Detailed
Running tests from 1 files.
Filter 'Tag' set to ('None').
Filters selected 1 tests to run.
Running tests from '...\real-life-tagging-scenarios.tests.ps1'
Describing Get-Beer
Context unit tests
[+] unit test 1 15ms
Tests completed in 269ms
Tests Passed: 1, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 6
You can combine None with real tags, for example -TagFilter "None", "Acceptance" runs the untagged tests and the acceptance tests.
None is a reserved filter value starting in Pester 6. If you use None as a real tag, filtering by it now also selects — or, with -ExcludeTagFilter, skips — every untagged test. A test that is literally tagged None is still matched by the filter, so it is included (or excluded) together with the untagged tests.