diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2017-07-24 12:37:22 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 12:37:22 -0300 |
commit | e44284c1257495402ee94e79302ee54fc94552b7 (patch) | |
tree | 6d3429ce925a4b00d9716a2549429b35a970d485 | |
parent | 81ad185f0d0b2474120140246d756acc8e0530aa (diff) | |
parent | d0ecfdf00f951714058b629b21719cac2ab53c75 (diff) | |
download | pytest-e44284c1257495402ee94e79302ee54fc94552b7.tar.gz |
Merge pull request #2611 from segevfiner/patch-1
Early import colorama so that it get's the correct terminal
-rw-r--r-- | _pytest/capture.py | 19 | ||||
-rw-r--r-- | changelog/2510.bugfix | 1 |
2 files changed, 20 insertions, 0 deletions
diff --git a/_pytest/capture.py b/_pytest/capture.py index 481bc2549..b627e5102 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 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. |