pytest-sugar
pytest-sugar copied to clipboard
text dump instead of graph
I am seeing this instead of graph
\x1b[0m\x1b[32m\u2713\x1b[0m\x1b[32m\u2713\x1b[0m\x1b[32m\u2713\x1b[0m\x1b[32m\u2713\x1b[0m\x1b[32m\u2713\x1b[0m\x1b[32m\u2713\x1b[0m \x1b[32m98%...
Results (0.73s):
85 passed
The dump is very very long. It's supposed to be rendered to graph. I am inside a docker container, what could be the reason, please? I have tested color display, it's ok. The 85 passed part is in green.
Do you run docker with -it - if not, does that change anything?
Yes, I specified --rm -t -i, and then py.test interactively inside the docker container.
I'm seeing the same issue if I run tests inside docker, it looks like it is escaping the control character as \x1b perhaps? Very odd. I am using docker run -it ...
Here's some more data points:
>>> import sys
>>> sys.stdout.encoding
'ANSI_X3.4-1968'
>>> import py.io
>>> tw = py.io.TerminalWriter(sys.stdout)
>>> tw.write(u'\r \x1b[36mfilename.py\x1b[0mtest_name\x1b[0m \x1b[32m\u2713\x1b[0m\n\n')
\r \x1b[36mfilename.py\x1b[0mtest_name\x1b[0m \x1b[32m\u2713\x1b[0m\n\n>>>
Note how when the encoding is 'ANSI_X3.4-1968' it puts in the escape characters.
Outside of docker this works fine:
>>> import sys
>>> sys.stdout.encoding
'UTF-8'
>>> import py.io
>>> py.io.TerminalWriter(sys.stdout).write(u'\r \x1b[36mtest_file.py\x1b[0mtest_name\x1b[0m \x1b[32m\u2713\x1b[0m\n\n')
test_file.test_name ✓
Workaround:
# PYTHONIOENCODING=UTF-8 python
>>> import sys
>>> sys.stdout.encoding
'UTF-8'
>>> import py.io
>>> py.io.TerminalWriter(sys.stdout).write(u'\r \x1b[36mtest_file.py\x1b[0mtest_name\x1b[0m \x1b[32m\u2713\x1b[0m\n\n')
test_file.pytest_name ✓
So, setting PYTHONIOENCODING=UTF-8 seems to resolve the problem, as long as your terminal actually supports UTF-8 encoding.
I do wish I knew why sys.stdout.encoding was UTF-8 outside docker and ANSI_X3.4-1968 within.
ANSI_X3.4-1968 is a fancy way to say ASCII, so I'm guessing locale will show a C locale inside docker, i.e. the locale was not generated/configured properly.
Inside docker:
root@d4cf4ef0c83f:/# locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
Outside docker:
$ locale
LANG=en_CA.UTF-8
LANGUAGE=
LC_CTYPE="en_CA.UTF-8"
LC_NUMERIC="en_CA.UTF-8"
LC_TIME="en_CA.UTF-8"
LC_COLLATE="en_CA.UTF-8"
LC_MONETARY="en_CA.UTF-8"
LC_MESSAGES="en_CA.UTF-8"
LC_PAPER="en_CA.UTF-8"
LC_NAME="en_CA.UTF-8"
LC_ADDRESS="en_CA.UTF-8"
LC_TELEPHONE="en_CA.UTF-8"
LC_MEASUREMENT="en_CA.UTF-8"
LC_IDENTIFICATION="en_CA.UTF-8"
LC_ALL=
Anyway, it this point it's pretty clearly a docker issue, not a pytest-sugar issue. This issue should hopefully serve as a reference for other who run into this problem.
Or instead of setting PYTHONIOENCODING, setting up the locale correctly in the Dockerfile should work, and might help with other things that rely on locale as well:
# Set the locale
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
(from http://jaredmarkell.com/docker-and-locales/)
I've got this error too without using Docker but Tox.
$ tox -r -epy27
py27 recreate: /home/vagrant/Cloud/git/nimbus-sirocco/.tox/py27
py27 installdeps: -r/home/vagrant/Cloud/git/nimbus-sirocco/requirements.txt, -r/home/vagrant/Cloud/git/nimbus-sirocco/requirements-test.txt
py27 installed: apache-libcloud==0.14.0,cffi==1.6.0,cookies==2.2.1,coverage==4.1,cryptography==1.3.2,enum34==1.1.6,flasgger==0.5.12,Flask==0.10.1,Flask-Cache==0.13.1,flup6==1.1,functools32==3.2.3.post2,idna==2.1,ipaddress==1.0.16,itsdangerous==0.24,Jinja2==2.8,jsonschema==2.5.1,ldap3==0.9.8.4,libraries==3.2.2,MarkupSafe==0.23,mistune==0.7.2,mock==1.0.1,mysql-connector-python==2.0.4,netaddr==0.7.18,py==1.4.31,pyasn1==0.1.9,pycparser==2.14,pyOpenSSL==0.15.1,pytest==2.9.2,pytest-cov==2.2.0,pytest-sugar==0.7.1,pyvmomi==6.0.0.2016.4,PyYAML==3.11,requests==2.7.0,responses==0.5.1,six==1.9.0,termcolor==1.1.0,vmware-api==3.16.0,Werkzeug==0.11.10
py27 runtests: PYTHONHASHSEED='2820986654'
py27 runtests: commands[0] | py.test --ignore=venv
Test session starts (platform: linux2, Python 2.7.10, pytest 2.9.2, pytest-sugar 0.7.1)
rootdir: /home/vagrant/Cloud/git/nimbus-sirocco, inifile:
plugins: cov-2.2.0, sugar-0.7.1
\r \x1b[36mnimbussirocco/integration_tests/api/v1/\x1b[0mtest_api_catalog.py\x1b[0m \x1b[32m\u2713\x1b[0m \x1b[32m1% \x1b[0m\x1b[40m\x1b[32m\u258f\x1b[0m\x1b[40m\x1b[32m \x1b[0m\r \x1b[36mnimbussirocco/integration_tests/api/v1/\x1b[0mtest_api_catalog.py\x1b[0m \x1b[32m\u2713\x1b[0m\x1b[32m\u2713\x1b[0m \x1b[32m1% \x1b[0m\x1b[40m\x1b[32m\u258e\x1b[0m\x1b
But if i use directly py.test it works :
$ .tox/py27/bin/py.test --ignore=venv
Test session starts (platform: linux2, Python 2.7.10, pytest 2.9.2, pytest-sugar 0.7.1)
rootdir: /home/vagrant/Cloud/git/nimbus-sirocco, inifile:
plugins: cov-2.2.0, sugar-0.7.1
nimbussirocco/integration_tests/api/v1/test_api_catalog.py ✓✓ 1% ▎
Any idea how fix that ?
Just to add that this happens when the test is run on a jenkins server, as well if the output is sent to the browser.
Same thing happens to me on Windows 10 cmd.
@Sup3rGeo You might wanna take a look into https://github.com/Frozenball/pytest-sugar/pull/49#issuecomment-146567670