Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console default text and background colors are set to black #2510

Closed
jay-hennen opened this issue Jun 20, 2017 · 18 comments
Closed

Console default text and background colors are set to black #2510

jay-hennen opened this issue Jun 20, 2017 · 18 comments

Comments

@jay-hennen
Copy link

jay-hennen commented Jun 20, 2017

Hi, this is a real head-scratcher. The only references I can find to something with similar symptoms are issue #459 and #399, but I think my situation is caused by something unrelated.

The symptoms are, when I run pytest in certain situations, the screen text and background are both set to black which causes 'invisible output' (see pic). This seems to be a shell-independent problem (as in it happens in git bash, powershell, and cmd.
invisibletext

I finally distilled this issue down to the following: Loading the tornado.ioloop module in a conftest.py file (even if buried at the bottom of an import stack) will cause the background and screen text to be set to black. In my case, something in our project imported zmq.eventloop.ioloop which in turn imported tornado.ioloop

As far as I'm aware nobody else in the office has this problem, (and neither did I, until I got a new computer). For reference, I'm using Windows 10 Enterprise 64-bit v1607. Not sure where to go from here aside from digging into the conftest.py-handling code (or tornado.ioloop code)

Edit: I forgot to mention: I can edit the console properties and change the text back to the right color, which will cause all the 'invisible' text to reappear. However, this has to be done after each pytest run.

@The-Compiler
Copy link
Member

I see the same (without tornado involved) since a while already, haven't tested recently yet.

@nicoddemus
Copy link
Member

nicoddemus commented Jun 21, 2017

@jay-hennen if you have the time and can provide a small reproducible example, I can take a look. I've never experienced this myself or my colleagues (AFAIK) which are in majority also on Windows 10, so it is hard to figure out what might be the problem. ☹️

@jay-hennen
Copy link
Author

For me, it's quite easy to reproduce Run pytest from a folder that has the following:

  1. A dummy test_foo.py
  2. A conftest.py with a single line: import tornado.ioloop

That's as far as I got with distilling the issue out.

Unfortunately I don't know if this will cause the issue on your machines. It did not happen on my previous Windows 10 computer. Maybe the fact that it was an upgrade/migration from Win 7 while my current one is a 'fresh' install so to speak.

@nicoddemus
Copy link
Member

Thanks.

Hmm I actually see the problem in Python 3.6 but not in 2.7 on my Windows computer at work. Which Python are you using?

@jay-hennen
Copy link
Author

I am using Python 2.7.13 and pytest v3.1.0.

@nicoddemus
Copy link
Member

Heh lovely, I reproduce the problem in 3.6 but not on 2.7. 😋

I'll see if I can reproduce it from home.

@charlie-foxtrat
Copy link

Hi all,
I currently reproduced the said issue in Python 3.6.1 running in venv and pytest 3.1.2 using Windows 10. After running it, the terminal window becomes totally black.

pytest

I also tried to change my terminal's background color to white but generated the same problem.

pytest bgrnd

I also have a conftest.py but do not have tornado.ioloop.
I can confirm that it is shell-independent since I was able to reproduce the issue using git bash, cmd and powershell.
It works however when ran under windows subsystem for linux, and on ubuntu machines.

Current workarounds on windows are either using windows subsystem for linux or by printing the outputs to a textfile using 'pytest file.py > file.txt'

@nicoddemus
Copy link
Member

nicoddemus commented Jun 22, 2017 via email

@charlie-foxtrat
Copy link

charlie-foxtrat commented Jun 22, 2017

conftest.py (the app that I have imported here is an instance of flask)

""" conftest """
import pytest
from app import app

@pytest.fixture
def client(request):
    app.testing = True
    test_client = app.test_client()

    def teardown():
        pass

    request.addfinalizer(teardown)
    return test_client

as for my test.py it was just a simple assertion test on my projects root folder beside the conftest.py.

test.py

def add(x):
    x = x + 1
    return x


def test_add():
    sum = add(1)
    assert sum == 3

I tried removing my import of app and the terminal display worked properly again, so for my case I think the issue has something to do with flask.

Edit: can confirm that flask is the problem for me,I tried importing flask directly and the issue remained

import pytest
from flask import Flask

@pytest.fixture
def client(request):
    app = Flask(__name__)
    app.testing = True
    test_client = app.test_client()

    def teardown():
        pass

    request.addfinalizer(teardown)
    return test_client

@nicoddemus
Copy link
Member

Thanks! Sorry about not being clear, I meant to ask for a reproducible example. 😁

But I managed to reproduce the problem (again in 3.6) just by importing flask in conftest.py, which is very interesting.

@RonnyPfannschmidt
Copy link
Member

@nicoddemus i suspect could be double init of colorama via click

@nicoddemus
Copy link
Member

@RonnyPfannschmidt yeah, colorama also came to my mind because flask does depend on click... 👍

@jay-hennen
Copy link
Author

Here's a data point for you: tornado does not seem to have colorama as a dependency (maybe optional??)

conda create --dry-run --json -n dummy tornado
{
"actions": {
"LINK": [
"vs2008_runtime-9.00.30729.5054-0 1",
"conda-forge::python-2.7.13-1 1",
"conda-forge::backports_abc-0.5-py27_0 1",
"conda-forge::certifi-2017.4.17-py27_0 1",
"conda-forge::six-1.10.0-py27_1 1",
"conda-forge::ssl_match_hostname-3.5.0.1-py27_1 1",
"conda-forge::wincertstore-0.2-py27_0 1",
"conda-forge::setuptools-33.1.1-py27_0 1",
"conda-forge::singledispatch-3.4.0.3-py27_0 1",
"conda-forge::tornado-4.5.1-py27_0 1",
"conda-forge::wheel-0.29.0-py27_0 1",
"conda-forge::pip-9.0.1-py27_0 1"
],
}

Also, IIRC import tornado works fine. It's specifically importing tornado.ioloop that causes the issue

@jay-hennen
Copy link
Author

Just noticed that if you pause during a pytest run using something like pdb and then fix the console colors, they will break again after printing the success or failure message. Appears like this color change gets triggered sometime before the collected tests are run and then once more after they all finish.

@ghost
Copy link

ghost commented Jul 14, 2017

@jay-hennen tornado.ioloop imports a few items from tornado.log which uses colorama if its available; importing tornado does not do this. So colorama is still the most likely point of contact between the two cases.

@nicoddemus
Copy link
Member

Yep, definitely. I can reproduce with:

# conftest.py
import colorama

# test_foo.py
def test():
    pass

If I move the colorama import from conftest.py into the test module, the problem disappears.

@jay-hennen
Copy link
Author

So it's colorama then?? What a roundabout way for it to mess things up. Good job finding that!

@nicoddemus
Copy link
Member

Fixed by #2611

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants