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,20 @@ 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
TRANSFORMED = { value = "{USER}/alpha", transform = true }
46
+
SKIP_IF_SET = { value = "on", skip_if_set = true }
47
+
DATABASE_URL = { unset = true }
46
48
```
47
49
48
-
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:
50
+
The `tool.pytest_env` (`pytest_env` in `pytest.toml` and `.pytest.toml`) tables keys are the environment variables keys
51
+
to set. The right hand side of the assignment:
49
52
50
-
- if an inline table you can set options via the `transform`or `skip_if_set` keys, while the `value` key holds the
51
-
value to set (or transform before setting). For transformation the variables you can use is other environment
53
+
- if an inline table you can set options via the `transform`, `skip_if_set`or `unset` keys, while the `value` key holds
54
+
the value to set (or transform before setting). For transformation the variables you can use is other environment
52
55
variable,
53
56
- otherwise the value to set for the environment variable to set (casted to a string).
54
57
@@ -69,8 +72,8 @@ Or with `pyproject.toml`:
69
72
```toml
70
73
[tool.pytest.ini_options]
71
74
env = [
72
-
"HOME=~/tmp",
73
-
"RUN_ENV=test",
75
+
"HOME=~/tmp",
76
+
"RUN_ENV=test",
74
77
]
75
78
```
76
79
@@ -105,3 +108,14 @@ env =
105
108
R:RUN_PATH=/run/path/{USER}
106
109
R:D:RUN_PATH_IF_NOT_SET=/run/path/{USER}
107
110
```
111
+
112
+
### Unsetting variables
113
+
114
+
You can use `U:` (unset) as prefix to remove an environment variable. This differs from setting a variable to an empty
115
+
string — the variable will be completely removed from `os.environ`:
0 commit comments