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
This is a `pytest` plugin that enables you to set environment variables in `pytest.ini`, `pyproject.toml`, `pytest.toml` or `.pytest.toml` files.
8
+
This is a `pytest` plugin that enables you to set environment variables in `pytest.ini`, `pyproject.toml`, `pytest.toml`
9
+
or `.pytest.toml` files.
10
10
11
11
## Installation
12
12
@@ -20,19 +20,19 @@ pip install pytest-env
20
20
21
21
### Native form in `pyproject.toml`, `pytest.toml` and `.pytest.toml`
22
22
23
-
> [!NOTE]
24
-
> `pytest.toml` and `.pytest.toml` is only supported on Pytest 9.0+.
23
+
> [!NOTE]`pytest.toml` and `.pytest.toml` is only supported on Pytest 9.0+.
25
24
26
-
Native form takes precedence over the `pytest.ini` form. `pytest.toml` takes precedence over `.pytest.toml`, and that takes precedence over `pyproject.toml`.
25
+
Native form takes precedence over the `pytest.ini` form. `pytest.toml` takes precedence over `.pytest.toml`, and that
The `tool.pytest_env` (`pytest_env` in `pytest.toml` and `.pytest.toml`) tables keys are the environment variables keys to set. The right hand side of the assignment:
48
+
The `tool.pytest_env` (`pytest_env` in `pytest.toml` and `.pytest.toml`) tables keys are the environment variables keys
49
+
to set. The right hand side of the assignment:
49
50
50
51
- if an inline table you can set options via the `transform` or `skip_if_set` keys, while the `value` key holds the
51
52
value to set (or transform before setting). For transformation the variables you can use is other environment
52
53
variable,
53
54
- otherwise the value to set for the environment variable to set (casted to a string).
54
55
56
+
### Configuration file discovery
57
+
58
+
When using the native TOML form, `pytest-env` walks the directory tree starting from the directory containing the
59
+
configuration file pytest resolved (`inipath`). For each directory it checks, in order: `pytest.toml`, `.pytest.toml`,
60
+
and `pyproject.toml`. It stops at the first file that contains a `[pytest_env]` (or `[tool.pytest_env]` for
61
+
`pyproject.toml`) section.
62
+
63
+
This means a subdirectory with its own `pytest.toml` containing `[pytest_env]` takes precedence over a parent
64
+
`pyproject.toml` with `[tool.pytest_env]`, as long as pytest resolves its config to that subdirectory:
0 commit comments