Skip to content

Commit

Permalink
Add a few more unit tests for "FORCE_COLOR" / "NO_COLOR"
Browse files Browse the repository at this point in the history
  • Loading branch information
Delgan committed Feb 20, 2025
1 parent c22a981 commit 0a0985b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/test_add_option_colorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,12 @@ def test_override_no_color(monkeypatch):
logger.add(stream, format="<blue>{message}</blue>", colorize=True)
logger.debug("Message", colorize=False)
assert stream.getvalue() == parse("<blue>Message</blue>\n")


def test_override_force_color(monkeypatch):
stream = StreamIsattyFalse()
with monkeypatch.context() as context:
context.setitem(os.environ, "FORCE_COLOR", "1")
logger.add(stream, format="<blue>{message}</blue>", colorize=False)
logger.debug("Message", colorize=False)
assert stream.getvalue() == "Message\n"
15 changes: 15 additions & 0 deletions tests/test_colorama.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,21 @@ def test_honor_force_color_standard(monkeypatch, patched, force_color, expected)
assert should_colorize(stream) is expected


def test_no_color_takes_precedence_over_force_color(monkeypatch):
stream_tty = StreamIsattyTrue()
stream_not_tty = StreamIsattyFalse()

with monkeypatch.context() as context:
context.setitem(os.environ, "NO_COLOR", "1")
context.setitem(os.environ, "FORCE_COLOR", "1")

context.setattr(sys, "__stderr__", stream_tty, raising=False)
assert not should_colorize(stream_tty)

context.setattr(sys, "__stderr__", stream_not_tty, raising=False)
assert not should_colorize(stream_not_tty)


@pytest.mark.parametrize(
("patched", "expected"),
[
Expand Down

0 comments on commit 0a0985b

Please sign in to comment.