@@ -303,3 +303,39 @@ def test_should_do_markup_PY_COLORS_eq_0(monkeypatch):
303303 tw.line("hello", bold=True)
304304 s = f.getvalue()
305305 assert s == "hello\n"
306+
307+ def test_should_do_markup(monkeypatch):
308+ monkeypatch.delenv("PY_COLORS", raising=False)
309+ monkeypatch.delenv("NO_COLOR", raising=False)
310+
311+ should_do_markup = terminalwriter.should_do_markup
312+
313+ f = py.io.TextIO()
314+ f.isatty = lambda: True
315+
316+ assert should_do_markup(f) is True
317+
318+ # NO_COLOR without PY_COLORS.
319+ monkeypatch.setenv("NO_COLOR", "0")
320+ assert should_do_markup(f) is False
321+ monkeypatch.setenv("NO_COLOR", "1")
322+ assert should_do_markup(f) is False
323+ monkeypatch.setenv("NO_COLOR", "any")
324+ assert should_do_markup(f) is False
325+
326+ # PY_COLORS overrides NO_COLOR ("0" and "1" only).
327+ monkeypatch.setenv("PY_COLORS", "1")
328+ assert should_do_markup(f) is True
329+ monkeypatch.setenv("PY_COLORS", "0")
330+ assert should_do_markup(f) is False
331+ # Uses NO_COLOR.
332+ monkeypatch.setenv("PY_COLORS", "any")
333+ assert should_do_markup(f) is False
334+ monkeypatch.delenv("NO_COLOR")
335+ assert should_do_markup(f) is True
336+
337+ # Back to defaults.
338+ monkeypatch.delenv("PY_COLORS")
339+ assert should_do_markup(f) is True
340+ f.isatty = lambda: False
341+ assert should_do_markup(f) is False
0 commit comments