Skip to content

Commit

Permalink
Merge pull request #2611 from segevfiner/patch-1
Browse files Browse the repository at this point in the history
Early import colorama so that it get's the correct terminal
  • Loading branch information
nicoddemus authored Jul 24, 2017
2 parents 81ad185 + d0ecfdf commit e44284c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions _pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -473,6 +474,24 @@ def buffer(self):
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
Expand Down
1 change: 1 addition & 0 deletions changelog/2510.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix terminal color changing to black on Windows if ``colorama`` is imported in a ``conftest.py`` file.

0 comments on commit e44284c

Please sign in to comment.