MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _update_current_test_var

Function _update_current_test_var

src/_pytest/runner.py:185–199  ·  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: Optional["Literal['setup', 'call', 'teardown']"]
)

Source from the content-addressed store, hash-verified

183
184
185def _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
202def pytest_report_teststatus(report: BaseReport) -> Optional[Tuple[str, str, str]]:

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