pytest-sugar icon indicating copy to clipboard operation
pytest-sugar copied to clipboard

text dump instead of graph

Open zyxue opened this issue 8 years ago • 13 comments

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.

zyxue avatar Apr 26 '16 22:04 zyxue

Do you run docker with -it - if not, does that change anything?

The-Compiler avatar Apr 27 '16 04:04 The-Compiler

Yes, I specified --rm -t -i, and then py.test interactively inside the docker container.

zyxue avatar Apr 27 '16 15:04 zyxue

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 ...

dobesv avatar May 10 '16 01:05 dobesv

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 ✓

dobesv avatar May 11 '16 00:05 dobesv

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.

dobesv avatar May 11 '16 01:05 dobesv

I do wish I knew why sys.stdout.encoding was UTF-8 outside docker and ANSI_X3.4-1968 within.

dobesv avatar May 11 '16 02:05 dobesv

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.

The-Compiler avatar May 11 '16 03:05 The-Compiler

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.

dobesv avatar May 12 '16 00:05 dobesv

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/)

dobesv avatar May 12 '16 00:05 dobesv

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 ?

nlamirault avatar Jun 22 '16 11:06 nlamirault

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.

zyxue avatar Jun 22 '16 15:06 zyxue

Same thing happens to me on Windows 10 cmd.

Sup3rGeo avatar Oct 23 '17 09:10 Sup3rGeo

@Sup3rGeo You might wanna take a look into https://github.com/Frozenball/pytest-sugar/pull/49#issuecomment-146567670

Teemu avatar Oct 17 '18 19:10 Teemu