diff --git a/README.md b/README.md index 4a159ad..a6e1f36 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,8 @@ Color output is enabled by default in Refurb. To disable it, do one of the follo * Set `color = false` in the config file. +* Pipe/redirect Refurb output to another program or file. + ## Developing / Contributing ### Setup diff --git a/refurb/settings.py b/refurb/settings.py index aa185f3..6e69881 100644 --- a/refurb/settings.py +++ b/refurb/settings.py @@ -52,7 +52,7 @@ def __post_init__(self) -> None: 'refurb: "enable all" and "disable all" can\'t be used at the same time' # noqa: E501 ) - if os.getenv("NO_COLOR"): + if os.getenv("NO_COLOR") or not sys.stdout.isatty(): self.color = False @staticmethod diff --git a/test/conftest.py b/test/conftest.py new file mode 100644 index 0000000..02947c9 --- /dev/null +++ b/test/conftest.py @@ -0,0 +1,10 @@ +from unittest.mock import patch +import pytest + +@pytest.fixture(autouse=True) +def fake_tty(): + # Pytest doesnt run in a TTY, so the new TTY detection code is causing a lot of color related + # tests to fail. This hack makes it so color is always enabled, like it would in a normal TTY. + with patch("sys.stdout.isatty") as p: + p.return_value = True + yield p