Skip to content

Commit 2292f3b

Browse files
Improve docs for Filters in ExUnit (:exclude and :include configuration) (#15118)
1 parent a2a669e commit 2292f3b

2 files changed

Lines changed: 36 additions & 34 deletions

File tree

lib/ex_unit/lib/ex_unit.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ defmodule ExUnit do
328328
defaults to `IO.ANSI.color_background(0, 2, 0)`;
329329
330330
* `:exclude` - specifies which tests are run by skipping tests that match the
331-
filter. See the "Filters" section in the documentation for `ExUnit.Case`;
331+
filter. For more information, see the "Tags" and "Filters" sections in the
332+
documentation for `ExUnit.Case`;
332333
333334
* `:exit_status` - specifies an alternate exit status to use when the test
334335
suite fails. Defaults to `2`;
@@ -342,8 +343,9 @@ defmodule ExUnit do
342343
* `:include` - specifies which tests are run by skipping tests that do not
343344
match the filter. Keep in mind that all tests are included by default, so unless they are
344345
excluded first, the `:include` option has no effect. To only run the tests
345-
that match the `:include` filter, exclude the `:test` tag first (see the
346-
documentation for `ExUnit.Case` for more information on tags and filters);
346+
that match the `:include` filter, exclude the `:test` tag first.
347+
For more information, see the "Tags" and "Filters" sections in the
348+
documentation for `ExUnit.Case`;
347349
348350
* `:max_cases` - maximum number of tests to run in parallel. Only tests from
349351
different modules run in parallel. It defaults to `System.schedulers_online * 2`

lib/ex_unit/lib/ex_unit/case.ex

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,37 @@ defmodule ExUnit.Case do
196196
197197
* `:tmp_dir` - (since v1.11.0) see the "Tmp Dir" section below
198198
199+
## Filters
200+
201+
Tags can also be used to identify specific tests, which can then
202+
be included or excluded using filters. The most common functionality
203+
is to exclude some particular tests from running, which can be done
204+
via `ExUnit.configure/1`:
205+
206+
# Exclude all external tests from running
207+
ExUnit.configure(exclude: [external: true])
208+
209+
From now on, ExUnit will not run any test that has the `:external` option
210+
set to `true`. This behaviour can be reversed with the `:include` option
211+
which is usually passed through the command line:
212+
213+
$ mix test --include external:true
214+
215+
Run `mix help test` for more information on how to run filters via Mix.
216+
217+
Another use case for tags and filters is to exclude all tests that have
218+
a particular tag by default, regardless of its value, and include only
219+
a certain subset:
220+
221+
ExUnit.configure(exclude: :os, include: [os: :unix])
222+
223+
A given include/exclude filter can be given more than once:
224+
225+
ExUnit.configure(exclude: [os: :unix, os: :windows])
226+
227+
Keep in mind that all tests are included by default, so unless they are
228+
excluded first, the `include` option has no effect.
229+
199230
## Parameterized tests
200231
201232
Sometimes you want to run the same tests but with different parameters.
@@ -231,37 +262,6 @@ defmodule ExUnit.Case do
231262
may be the wrong solution to your problem. Consider creating separated
232263
tests and sharing logic between them using regular functions
233264
234-
## Filters
235-
236-
Tags can also be used to identify specific tests, which can then
237-
be included or excluded using filters. The most common functionality
238-
is to exclude some particular tests from running, which can be done
239-
via `ExUnit.configure/1`:
240-
241-
# Exclude all external tests from running
242-
ExUnit.configure(exclude: [external: true])
243-
244-
From now on, ExUnit will not run any test that has the `:external` option
245-
set to `true`. This behaviour can be reversed with the `:include` option
246-
which is usually passed through the command line:
247-
248-
$ mix test --include external:true
249-
250-
Run `mix help test` for more information on how to run filters via Mix.
251-
252-
Another use case for tags and filters is to exclude all tests that have
253-
a particular tag by default, regardless of its value, and include only
254-
a certain subset:
255-
256-
ExUnit.configure(exclude: :os, include: [os: :unix])
257-
258-
A given include/exclude filter can be given more than once:
259-
260-
ExUnit.configure(exclude: [os: :unix, os: :windows])
261-
262-
Keep in mind that all tests are included by default, so unless they are
263-
excluded first, the `include` option has no effect.
264-
265265
## Log Capture
266266
267267
ExUnit can optionally suppress printing of log messages that are generated

0 commit comments

Comments
 (0)