KogenCredo.Check.Warning.GlobalStateInAsync (KogenCredo v0.1.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of low and works with any version of Elixir.

Explanation

Async test modules must not write node-wide state. Application env, System.put_env, global mocks, named ETS tables, fixed file paths, Logger.configure and :persistent_term.put leak into concurrently running modules.

Bad:

use ExUnit.Case, async: true
setup do: Application.put_env(:my_app, :mode, :test)

Good:

use ExUnit.Case, async: true, group: :my_app_mode

or async: false with @moduletag serial: :env.

Check-Specific Parameters

Use the following parameters to configure this check:

:case_templates

Map of case template module name => :inherit | :async | :serial.

This parameter defaults to %{}.

:kinds

Kinds of global state to report.

This parameter defaults to [:env, :mock_global, :ets, :file, :cwd, :logger, :persistent_term].

:included_files

Path globs of files to check.

This parameter defaults to ["test/**/*_test.exs"].

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.