MCPcopy
hub / github.com/pytest-dev/pytest / _update_current_test_var

Function _update_current_test_var

src/_pytest/runner.py:203–217  ·  view source on GitHub ↗

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: Literal["setup", "call", "teardown"] | None
)

Source from the content-addressed store, hash-verified

201
202
203def _update_current_test_var(
204 item: Item, when: Literal["setup", "call", "teardown"] | None
205) -> None:
206 """Update :envvar:`PYTEST_CURRENT_TEST` to reflect the current item and stage.
207
208 If ``when`` is None, delete ``PYTEST_CURRENT_TEST`` from the environment.
209 """
210 var_name = "PYTEST_CURRENT_TEST"
211 if when:
212 value = f"{item.nodeid} ({when})"
213 # don't allow null bytes on environment variables (see #2644, #2957)
214 value = value.replace("\x00", "(null)")
215 os.environ[var_name] = value
216 else:
217 os.environ.pop(var_name)
218
219
220def pytest_report_teststatus(report: BaseReport) -> tuple[str, str, str] | None:

Callers 3

pytest_runtest_setupFunction · 0.85
pytest_runtest_callFunction · 0.85
pytest_runtest_teardownFunction · 0.85

Calls 1

popMethod · 0.80

Tested by

no test coverage detected