2017-06-30 2 views
2

ich nosetests bin mit Test laufen, aber ich finde, dass es nicht die reale Unicode drucken:Wie man Nasetests drucken kann Unicode lesbar drucken?

#!/usr/bin/env python 
# encoding: utf-8 

import unittest 

class FooTests(unittest.TestCase): 
    def test_str(self): 
     print("中国") 
     self.assertEqual(1, 0) 

    def test_unicode(self): 
     print(u"中国") 
     self.assertEqual(1, 0) 

def main(): 
    unittest.main() 

if __name__ == "__main__": 
    main() 

seine erfassten Ergebnis ist wie folgt:

-------------------- >> begin captured stdout << --------------------- 
\u4e2d\u56fd 

--------------------- >> end captured stdout << ---------------------- 

Was ich will, ist:

-------------------- >> begin captured stdout << --------------------- 
中国 

--------------------- >> end captured stdout << ---------------------- 

Antwort

0

Die Angabe der Option -s oder --nocapture verhindert, dass nosetest die Standardausgabe erfasst; Sie werden die Zeichenfolge sehen, wie Sie wollen, aber ohne >> beging/end captured stdout<< Marker als print statemnet werden die Zeichenfolge gedruckt werden, sobald sie ausgeführt hat:

$ nosetests -s t.py 
中国 
F中国 
F 
====================================================================== 
FAIL: test_str (t.FooTests) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/tmp/t.py", line 9, in test_str 
    self.assertEqual(1, 0) 
AssertionError: 1 != 0 

====================================================================== 
FAIL: test_unicode (t.FooTests) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/tmp/t.py", line 13, in test_unicode 
    self.assertEqual(1, 0) 
AssertionError: 1 != 0 

---------------------------------------------------------------------- 
Ran 2 tests in 0.000s 

FAILED (failures=2) 

Eine andere Optionen: Verwenden Sie Python 3! Keine Option ist erforderlich:

$ python3 -m nose t.py 
FF 
====================================================================== 
FAIL: test_str (t.FooTests) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/tmp/t.py", line 9, in test_str 
    self.assertEqual(1, 0) 
AssertionError: 1 != 0 
-------------------- >> begin captured stdout << --------------------- 
中国 

--------------------- >> end captured stdout << ---------------------- 

====================================================================== 
FAIL: test_unicode (t.FooTests) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "/tmp/t.py", line 13, in test_unicode 
    self.assertEqual(1, 0) 
AssertionError: 1 != 0 
-------------------- >> begin captured stdout << --------------------- 
中国 

--------------------- >> end captured stdout << ---------------------- 

---------------------------------------------------------------------- 
Ran 2 tests in 0.001s 

FAILED (failures=2) 
Verwandte Themen