Re: Encoding problem while generating junit report file

311 views
Skip to first unread message

Pekka Klärck

unread,
Jun 17, 2012, 5:21:22 PM6/17/12
to fabrice....@gmail.com, robotframe...@googlegroups.com
2012/6/15 Fabio <fabrice....@gmail.com>:
>
> Now, i get an encoding error each time I run pybot, while the system is
> generating the junit report file.

I was able to reproduce the problem. In practice creating xunit
reports fails if a test has failed with a message containing non-ASCII
characters. This seems to be a regression in RF 2.7.2, or at least I
wasn't able to reproduce it with RF 2.7.1.

Could you submit an issue about this problem to the tracker? Fixing
the bug seems to be pretty simple and we ought to be able to get the
fix into 2.7.3.

> Let me take an example to explain my issue.
> First, I have an external utf-8 encoded variable file (I had to add the "u"
> caracter to make python understand that the string contains utf-8 caracters)
> :
>
> # -*- coding: utf-8 -*-
> MY_UTF8_VARIABLE = u"Changer un robinet est une opération délicate\r\nque
> vous pouvez entreprendre vous-même en étant organisé et\r\nrigoureux.
> Changer un robinet de radiateur peut être l’occasion de\r\nremplacer
> l’ancien modèle par un robinet thermostatique qui vous\r\nap"

Actually that "u" made the string Unicode in Python. Declaring UTF-8
encoding in the file allowed you to use non-ASCII characters to create
it. Otherwise you would have needed to escape them line \ue4. This
doesn't really have anything to with the bug you reported, though, and
you don't actually even need a variable file to reproduce it. Having
something like this in your test case file is enough:

*** Test Cases ***
Example
Fail Hyvää yötä

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Fabio

unread,
Jun 18, 2012, 3:22:45 AM6/18/12
to robotframe...@googlegroups.com, fabrice....@gmail.com
Hi,

Many thanks Pekka for taking time to answer.
Ok, I'll submit the defect.

Non adding the "u" caracter makes avoid me to use the variable as a KeyWord argument. I get then the following error :

> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 29: ordinal not in range(128).

It acts as the RF file was working in ascii and not in utf-8.

Fabrice.



Le dimanche 17 juin 2012 23:21:22 UTC+2, Pekka Klärck a écrit :
2012/6/15 Fabio :

Pekka Klärck

unread,
Jun 18, 2012, 3:54:24 AM6/18/12
to fabrice....@gmail.com, robotframe...@googlegroups.com
2012/6/18 Fabio <fabrice....@gmail.com>:
>
> Many thanks Pekka for taking time to answer.
> Ok, I'll submit the defect.

Great!


> Non adding the "u" caracter makes avoid me to use the variable as a KeyWord
> argument. I get then the following error :
>
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 29:
>> ordinal not in range(128).
>
> It acts as the RF file was working in ascii and not in utf-8.

You definitely need to have that "u" there. Without it your string
will be bytes, not Unicode, in Python. Notice that Unicode and UTF-8
are not the same, though. To understand the difference, you may want
to read great "The Absolute Minimum Every Software Developer
Absolutely, Positively Must Know About Unicode and Character Sets (No
Excuses!)" article by Joel Spolsky [1]. To understand Unicode in
Python better, including that "u" and also source code encoding, you
should also take a look at "Unicode HOWTO" [2].

[1] http://www.joelonsoftware.com/articles/Unicode.html
[2] http://docs.python.org/howto/unicode.html

Fabio

unread,
Jun 18, 2012, 4:50:45 AM6/18/12
to robotframe...@googlegroups.com

Thanks for the links. It was an interessing reading.

I've submited the issue : http://code.google.com/p/robotframework/issues/detail?id=1162 (indeed it works fine in 2.7.1 ... back to this version thus).

Thanks again for your help.

Fabrice

Le vendredi 15 juin 2012 17:11:48 UTC+2, Fabio a écrit :
Hi,

I'm currently using robotframework to test BackOffice jobs, that get data from external source and insert them into a database.
It worked fine since I decided to use a python file to store my test data.


Now, i get an encoding error each time I run pybot, while the system is generating the junit report file.

Let me take an example to explain my issue.
First, I have an external utf-8 encoded variable file (I had to add the "u" caracter to make python understand that the string contains utf-8 caracters) :

# -*- coding: utf-8 -*-
MY_UTF8_VARIABLE = u"Changer un robinet est une opération délicate\r\nque vous pouvez entreprendre vous-même en étant organisé et\r\nrigoureux. Changer un robinet de radiateur peut être l’occasion de\r\nremplacer l’ancien modèle par un robinet thermostatique qui vous\r\nap"

My Test Suite looks like this :

*** Settings ***
Variables        variablesUtf8.py

*** Test Cases ***
Test Encoding
    Log        ${MY_UTF8_VARIABLE}
    Should Be Equal As Strings        ${MY_UTF8_VARIABLE}        Different Value From Variable's


And the command I run is like :

> pybot --suite TS_Encoding --splitlog -x junitreport.xml ./

I get the following result :

==============================================================================
Poc                                                                          
==============================================================================
Poc.TS Encoding                                                              
==============================================================================
Test Encoding                                                         | FAIL |

Changer un robinet est une opération délicate
que vous pouvez entreprendre vous-même en étant organisé et
rigoureux. Changer un robinet de radiateur peut être l’occasion de
remplacer l’ancien modèle par un robinet thermostatique qui vous
ap != Different Value From Variable's
------------------------------------------------------------------------------
Poc.TS Encoding                                                       | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Poc                                                                   | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  /home/depaulis/pagesjaunes/projets/ILO_BO/ILO_SVN/recette/robotframework/poc/output.xml
[ ERROR ] Unexpected error: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 47: ordinal not in range(128)
Traceback (most recent call last):
  None

If I don't add the "-x" option, it works fine.
Does anybody have a clue about this issue ?

Thanks in advance,
Fabrice.

Reply all
Reply to author
Forward
0 new messages