Update :envvar:`PYTEST_CURRENT_TEST` to reflect the current item and stage. If ``when`` is None, delete ``PYTEST_CURRENT_TEST`` from the environment.
(
item: Item, when: Optional["Literal['setup', 'call', 'teardown']"]
)
| 183 | |
| 184 | |
| 185 | def _update_current_test_var( |
| 186 | item: Item, when: Optional["Literal['setup', 'call', 'teardown']"] |
| 187 | ) -> None: |
| 188 | """Update :envvar:`PYTEST_CURRENT_TEST` to reflect the current item and stage. |
| 189 | |
| 190 | If ``when`` is None, delete ``PYTEST_CURRENT_TEST`` from the environment. |
| 191 | """ |
| 192 | var_name = "PYTEST_CURRENT_TEST" |
| 193 | if when: |
| 194 | value = f"{item.nodeid} ({when})" |
| 195 | # don't allow null bytes on environment variables (see #2644, #2957) |
| 196 | value = value.replace("\x00", "(null)") |
| 197 | os.environ[var_name] = value |
| 198 | else: |
| 199 | os.environ.pop(var_name) |
| 200 | |
| 201 | |
| 202 | def pytest_report_teststatus(report: BaseReport) -> Optional[Tuple[str, str, str]]: |
no test coverage detected