Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError when raising an exception with non-ascii characters #47

Closed
anthonywee opened this issue Jul 23, 2015 · 0 comments
Closed

Comments

@anthonywee
Copy link
Contributor

The Python 2.6 tests will fail with a UnicodeEncodeError if an exception is raised with non-ascii characters in the message.

For example, I updated the test_non_flaky_thing() test in test_example.py to include the non-ascii message in the exception:

@genty
class ExampleFlakyTestsWithUnicodeTestNames(ExampleFlakyTests):
    @genty_dataset('ascii name', 'ńőń ȁŝćȉȉ ŝƭȕƒƒ')
    def test_non_flaky_thing(self, message):
        self._threshold += 1
        if self._threshold < 1:
            raise Exception(
                "Threshold is not high enough: {0} vs {1} for '{2}'.".format(
                    self._threshold, 1, message),
            )

This caused a UnicodeEncodeError when running the Python 2.6 tests:

py26 runtests: PYTHONHASHSEED='2117695302'
py26 runtests: commands[0] | nosetests --with-flaky --exclude=pytest|test_options_example
....................................
===Flaky Test Report===

Traceback (most recent call last):
  File ".tox/py26/bin/nosetests", line 11, in <module>
    sys.exit(run_exit())
  File "/Users/awee/open_source/flaky_fork/flaky/.tox/py26/lib/python2.6/site-packages/nose/core.py", line 121, in __init__
    **extra_args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 817, in __init__
    self.runTests()
  File "/Users/awee/open_source/flaky_fork/flaky/.tox/py26/lib/python2.6/site-packages/nose/core.py", line 207, in runTests
    result = self.testRunner.run(self.test)
  File "/Users/awee/open_source/flaky_fork/flaky/.tox/py26/lib/python2.6/site-packages/nose/core.py", line 66, in run
    result.printErrors()
  File "/Users/awee/open_source/flaky_fork/flaky/.tox/py26/lib/python2.6/site-packages/nose/result.py", line 110, in printErrors
    self.config.plugins.report(self.stream)
  File "/Users/awee/open_source/flaky_fork/flaky/.tox/py26/lib/python2.6/site-packages/nose/plugins/manager.py", line 99, in __call__
    return self.call(*arg, **kw)
  File "/Users/awee/open_source/flaky_fork/flaky/.tox/py26/lib/python2.6/site-packages/nose/plugins/manager.py", line 167, in simple
    result = meth(*arg, **kw)
  File "/Users/awee/open_source/flaky_fork/flaky/flaky/flaky_nose_plugin.py", line 182, in report
    self._add_flaky_report(stream)
  File "/Users/awee/open_source/flaky_fork/flaky/flaky/_flaky_plugin.py", line 236, in _add_flaky_report
    stream.write(self._stream.getvalue())
UnicodeEncodeError: 'ascii' codec can't encode characters in position 760-762: ordinal not in range(128)
ERROR: InvocationError: '/Users/awee/open_source/flaky_fork/flaky/.tox/py26/bin/nosetests --with-flaky --exclude=pytest|test_options_example'
__________________________________________________________________________________ summary __________________________________________________________________________________
ERROR:   py26: commands failed
anthonywee added a commit to anthonywee/flaky that referenced this issue Jul 23, 2015
Fixes box#47.
Catch a UncodeEncodeError when writing to the stream, and encode using
utf-8 if needed.
anthonywee added a commit to anthonywee/flaky that referenced this issue Jul 24, 2015
anthonywee added a commit to anthonywee/flaky that referenced this issue Jul 24, 2015
Fixes box#47.
Catch a UncodeEncodeError when writing to the stream, and encode using
utf-8 if needed. Add a new util method ensure_byte_string().
anthonywee added a commit to anthonywee/flaky that referenced this issue Jul 28, 2015
Adding ensure_byte_string() and tests to utils (b8cb6f1 and 913061b)
introduced issues related to Python 3's differences with handling
text and byte strings. Limiting the scope of this fix to just
_add_flaky_report(), where we directly call encode if we hit the
UnicodeEncodeError.
anthonywee added a commit to anthonywee/flaky that referenced this issue Jul 29, 2015
Move note on fix for UnicodeEncodeError (box#47) from 2.1.1 release into Upcoming
section.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant