wolever / parameterized

Parameterized testing with any Python test framework
Other
833 stars 105 forks source link

UnicodeDecodeError if test method docstring contains non-ascii characters #109

Closed radiophysicist closed 3 years ago

radiophysicist commented 3 years ago

Hello, I catched UnicodeDecodeError in case test method has a docstring containing non-ascii UTF-8 symbols:

Traceback (most recent call last):
  File "/source/ivideon/api/tests/unittests/__main__.py", line 197, in <module>
    tornado.testing.main(verbosity=os.getenv('IVIDEON_TESTS_VERBOSITY', default=0))
  File "/source/.test_venv/local/lib/python2.7/site-packages/tornado/testing.py", line 732, in main
    unittest.main(defaultTest="all", argv=argv, **kwargs)
  File "/usr/lib/python2.7/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/usr/lib/python2.7/unittest/main.py", line 149, in parseArgs
    self.createTests()
  File "/usr/lib/python2.7/unittest/main.py", line 158, in createTests
    self.module)
  File "/usr/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.7/unittest/loader.py", line 115, in loadTestsFromName
    test = obj()
  File "/source/ivideon/api/tests/unittests/__main__.py", line 103, in all
    return unittest.defaultTestLoader.loadTestsFromNames(test_modules)
  File "/usr/lib/python2.7/unittest/loader.py", line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
  File "/usr/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
    module = __import__('.'.join(parts_copy))
  File "ivideon/api/tests/unittests/test_billing.py", line 1297, in <module>
    class MyTestCase(object):
  File "ivideon/api/tests/unittests/test_billing.py", line 1300, in MyTestCase
    'value2'
  File "/source/.test_venv/local/lib/python2.7/site-packages/parameterized/parameterized.py", line 517, in parameterized_expand_wrapper
    frame_locals[name].__doc__ = doc_func(f, num, p)
  File "/source/.test_venv/local/lib/python2.7/site-packages/parameterized/parameterized.py", line 265, in default_doc_func
    return "".join([first.rstrip(), args, suffix, nl, rest])
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)

python version is 2.7.12, parameterized version is 0.7.4, tests are run by nosetest. Minimal code to reproduce:

# coding: utf-8

class MyTestCase(object):

    @parameterized.expand([
        'value1',
        'value2'
    ])
    def test_with_docstring(self, param):
        """ Это док-стринг, содержащий не-ascii символы
        """
        pass
wolever commented 3 years ago

Fixed, and will be part of the 0.7.5 release later today!