Skip to content

Commit 8990538

Browse files
patchback[bot]ogriselwebknjaz
authored
Fix passenv CI in tox ini and make tests insensitive to the presence of the CI env variable (#13684) (#13694)
As discussed in #13684. --------- (cherry picked from commit bf92deb) Co-authored-by: Olivier Grisel <[email protected]> Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
1 parent ca676bf commit 8990538

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

changelog/13684.contrib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make pytest's own testsuite insensitive to the presence of the ``CI`` environment variable -- by :user:`ogrisel`.

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,9 @@ markers = [
426426
"slow",
427427
# experimental mark for all tests using pexpect
428428
"uses_pexpect",
429+
# Disables the `remove_ci_env_var` autouse fixture on a given test that
430+
# actually inspects whether the CI environment variable is set.
431+
"keep_ci_var",
429432
]
430433

431434
[tool.towncrier]

testing/conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,15 @@ def mock_timing(monkeypatch: MonkeyPatch):
237237
result = MockTiming()
238238
result.patch(monkeypatch)
239239
return result
240+
241+
242+
@pytest.fixture(autouse=True)
243+
def remove_ci_env_var(monkeypatch: MonkeyPatch, request: pytest.FixtureRequest) -> None:
244+
"""Make the test insensitive if it is running in CI or not.
245+
246+
Use `@pytest.mark.keep_ci_var` in a test to avoid applying this fixture, letting the test
247+
see the real `CI` variable (if present).
248+
"""
249+
has_keep_ci_mark = request.node.get_closest_marker("keep_ci_var") is not None
250+
if not has_keep_ci_mark:
251+
monkeypatch.delenv("CI", raising=False)

testing/python/approx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,10 +1085,10 @@ def test_map_over_nested_lists(self):
10851085
]
10861086

10871087
def test_map_over_mixed_sequence(self):
1088-
assert _recursive_sequence_map(sqrt, [4, (25, 64), [(49)]]) == [
1088+
assert _recursive_sequence_map(sqrt, [4, (25, 64), [49]]) == [
10891089
2,
10901090
(5, 8),
1091-
[(7)],
1091+
[7],
10921092
]
10931093

10941094
def test_map_over_sequence_like(self):

testing/test_faulthandler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def test_disabled():
7171
assert result.ret == 0
7272

7373

74+
@pytest.mark.keep_ci_var
7475
@pytest.mark.parametrize(
7576
"enabled",
7677
[

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ passenv =
5252
PYTEST_ADDOPTS
5353
TERM
5454
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST
55+
CI
5556
setenv =
5657
_PYTEST_TOX_DEFAULT_POSARGS={env:_PYTEST_TOX_POSARGS_DOCTESTING:} {env:_PYTEST_TOX_POSARGS_LSOF:} {env:_PYTEST_TOX_POSARGS_XDIST:} {env:_PYTEST_FILES:}
5758

0 commit comments

Comments
 (0)