From 43544a431ca958b411d6b84c7093f03e48461349 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 24 Jul 2017 15:17:39 +0300 Subject: [PATCH 1/4] Early import colorama so that it get's the correct terminal --- _pytest/capture.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/_pytest/capture.py b/_pytest/capture.py index 481bc2549..be93eef2b 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -37,6 +37,7 @@ def pytest_load_initial_conftests(early_config, parser, args): ns = early_config.known_args_namespace if ns.capture == "fd": _py36_windowsconsoleio_workaround() + _colorama_workaround() _readline_workaround() pluginmanager = early_config.pluginmanager capman = CaptureManager(ns.capture) @@ -473,6 +474,24 @@ class DontReadFromInput: raise AttributeError('redirected stdin has no attribute buffer') +def _colorama_workaround(): + """ + Ensure colorama is imported so that it attaches to the correct stdio + handles on Windows. + + colorama uses the terminal on import time. So if something does the + first import of colorama while I/O capture is active, colorama will + fail in various ways. + """ + + if not sys.platform.startswith('win32'): + return + try: + import colorama # noqa + except ImportError: + pass + + def _readline_workaround(): """ Ensure readline is imported so that it attaches to the correct stdio From df12500661e1408d247ff95193ad5a6dc7aaedbb Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 24 Jul 2017 15:28:20 +0300 Subject: [PATCH 2/4] Create 2611.bugfix --- changelog/2611.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/2611.bugfix diff --git a/changelog/2611.bugfix b/changelog/2611.bugfix new file mode 100644 index 000000000..a491ce959 --- /dev/null +++ b/changelog/2611.bugfix @@ -0,0 +1 @@ +Early import colorama so that it get's the correct terminal. From d90bef44cc2c0a84b300b730e5fddb22b9287c1d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Mon, 24 Jul 2017 09:31:16 -0300 Subject: [PATCH 3/4] Update changelog file for #2510 --- changelog/2510.bugfix | 1 + changelog/2611.bugfix | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 changelog/2510.bugfix delete mode 100644 changelog/2611.bugfix diff --git a/changelog/2510.bugfix b/changelog/2510.bugfix new file mode 100644 index 000000000..e6fcb7c74 --- /dev/null +++ b/changelog/2510.bugfix @@ -0,0 +1 @@ +Fix terminal color changing to black on Windows if ``colorama`` is imported in a ``conftest.py`` file. diff --git a/changelog/2611.bugfix b/changelog/2611.bugfix deleted file mode 100644 index a491ce959..000000000 --- a/changelog/2611.bugfix +++ /dev/null @@ -1 +0,0 @@ -Early import colorama so that it get's the correct terminal. From d0ecfdf00f951714058b629b21719cac2ab53c75 Mon Sep 17 00:00:00 2001 From: Segev Finer Date: Mon, 24 Jul 2017 16:55:50 +0300 Subject: [PATCH 4/4] Delete trailing whitespace --- _pytest/capture.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/capture.py b/_pytest/capture.py index be93eef2b..b627e5102 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -478,7 +478,7 @@ def _colorama_workaround(): """ Ensure colorama is imported so that it attaches to the correct stdio handles on Windows. - + colorama uses the terminal on import time. So if something does the first import of colorama while I/O capture is active, colorama will fail in various ways.