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

Function test_current_test_env_var

testing/test_runner.py:910–939  ·  view source on GitHub ↗
(pytester: Pytester, monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

908
909
910def test_current_test_env_var(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
911 pytest_current_test_vars: List[Tuple[str, str]] = []
912 monkeypatch.setattr(
913 sys, "pytest_current_test_vars", pytest_current_test_vars, raising=False
914 )
915 pytester.makepyfile(
916 """
917 import pytest
918 import sys
919 import os
920
921 @pytest.fixture
922 def fix():
923 sys.pytest_current_test_vars.append(('setup', os.environ['PYTEST_CURRENT_TEST']))
924 yield
925 sys.pytest_current_test_vars.append(('teardown', os.environ['PYTEST_CURRENT_TEST']))
926
927 def test(fix):
928 sys.pytest_current_test_vars.append(('call', os.environ['PYTEST_CURRENT_TEST']))
929 """
930 )
931 result = pytester.runpytest_inprocess()
932 assert result.ret == 0
933 test_id = "test_current_test_env_var.py::test"
934 assert pytest_current_test_vars == [
935 ("setup", test_id + " (setup)"),
936 ("call", test_id + " (call)"),
937 ("teardown", test_id + " (teardown)"),
938 ]
939 assert "PYTEST_CURRENT_TEST" not in os.environ
940
941
942class TestReportContents:

Callers

nothing calls this directly

Calls 3

setattrMethod · 0.80
makepyfileMethod · 0.45
runpytest_inprocessMethod · 0.45

Tested by

no test coverage detected