pytest 3.0.5 with cyrillic symbols

465 views Asked by At

I have a problem with displaying test names with russian text in file paths in pytest-3.0.5. When I run on pytest==2.9.2 - everything is OK:

py.test -s -q --collect-only

Output:

test_card.py::test_graphic_card[/root/test_cases/files/Кредитная_карта_мир_41.png]

But when I try to run the same command on pytest==3.0.5:

py.test -s -q --collect-only

Output:

test_card.py::test_graphic_card[/root/test_cases/files/\xd0\x9a\xd1\x80\xd0\xb5\xd0\xb4\xd0\xb8\xd1\x82\xd0\xbd\xd0\xb0\xd1\x8f_\xd0\xba\xd0\xb0\xd1\x80\xd1\x82\xd0\xb0_\xd0\xbc\xd0\xb8\xd1\x80_41.png]

What should I do to have py.test==3.0.5 display test names like displayed py.test==2.9.2?

1

There are 1 answers

0
Igor Korolev On BEST ANSWER

I looked at the pytest source code and found out, that in newest version of pytest when tests are collected, they are processed with recently added function "_escape_strings". In this function:

if isinstance(val, bytes):
    try:
        return val.encode('ascii')
    except UnicodeDecodeError:                     
        return val.encode('string-escape')
    else:
        return val.encode('unicode-escape')

I suppose this func is self-explained. Finally, I've solved my problem decoding and unescaping of results in final test report, e.g.:

result = "/root/test_cases/files/\xd0\x9a\xd1\x80\xd0\xb5\xd0\xb4\xd0\xb8\xd1\x82\xd0\xbd\xd0\xb0\xd1\x8f_\xd0\xba\xd0\xb0\xd1\x80\xd1\x82\xd0\xb0_\xd0\xbc\xd0\xb8\xd1\x80_41.png"
print result.decode('string-escape') 
Out: /root/test_cases/files/Кредитная_карта_мир_41.png