Skip to content

Commit 449d9da

Browse files
authored
chore: add support PYTEST_MERGIFY_ENABLED=true (#131)
CI=true is good to enable it by default in CI. But some tests may change their behavior when CI is set. For example in pytest, they use tox and ensure CI is not passed to the test suite. Enabling pytest-mergify breaks the test suite. This change introduces an alternative for user that can't rely on CI=true.
1 parent 86f8bbe commit 449d9da

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

pytest_mergify/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313

1414
def is_in_ci() -> bool:
15-
return strtobool(os.environ.get("CI", "false"))
15+
return strtobool(os.environ.get("CI", "false")) or strtobool(
16+
os.environ.get("PYTEST_MERGIFY_ENABLE", "false")
17+
)
1618

1719

1820
def get_ci_provider() -> typing.Optional[CIProviderT]:

tests/test_plugin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ def test_no_ci(pytester_with_spans: conftest.PytesterWithSpanT) -> None:
2121
assert all("Mergify" not in line for line in result.stdout.lines)
2222

2323

24+
@pytest.mark.parametrize("env", ("PYTEST_MERGIFY_ENABLED", "CI"))
25+
def test_enabled(
26+
env: str,
27+
pytester_with_spans: conftest.PytesterWithSpanT,
28+
monkeypatch: pytest.MonkeyPatch,
29+
) -> None:
30+
monkeypatch.delenv("CI", raising=False)
31+
result, spans = pytester_with_spans(setenv={env: "true"})
32+
assert spans is not None
33+
assert any("Mergify CI" in line for line in result.stdout.lines)
34+
35+
2436
def test_no_token(pytester_with_spans: conftest.PytesterWithSpanT) -> None:
2537
result, spans = pytester_with_spans()
2638
assert spans is not None

0 commit comments

Comments
 (0)