From 237ea1ac239229dbcb6bbc80ce887919fc621bd1 Mon Sep 17 00:00:00 2001 From: dj <112573278+dheerajck@users.noreply.github.com> Date: Sun, 7 Apr 2024 18:24:35 +0530 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Bruno Oliveira --- changelog/9502.improvement.rst | 2 +- testing/test_runner.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/changelog/9502.improvement.rst b/changelog/9502.improvement.rst index 7174d7dbf..2eaf6a727 100644 --- a/changelog/9502.improvement.rst +++ b/changelog/9502.improvement.rst @@ -1 +1 @@ -Added an environment variable which helps to check if a code is running from within a pytest run +Added :envvar:`PYTEST_VERSION` environment variable which is defined at the start of the pytest session and undefined afterwards. It contains the value of ``pytest.__version__``, and among other things can be used to easily check if code is running from within a pytest run. diff --git a/testing/test_runner.py b/testing/test_runner.py index ed5a0f80e..c4fb85a7e 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -1096,7 +1096,7 @@ def test_outcome_exception_bad_msg() -> None: assert str(excinfo.value) == expected -def test_pytest_version(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: +def test_pytest_version_env_var(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: pytester.makepyfile( """ import pytest @@ -1108,6 +1108,5 @@ def test_pytest_version(pytester: Pytester, monkeypatch: MonkeyPatch) -> None: """ ) result = pytester.runpytest_inprocess() - # assert result.ret == 0 assert result.ret == ExitCode.OK assert "PYTEST_VERSION" not in os.environ