Skip to content

UnicodeDecodeError in invalid assert statement #1331

Closed
@pelme

Description

@pelme
‹tempenv-55e831397233f› ~ → cat test_foo.py
# -*- coding: utf-8 -*-
assert 'ål', in 'a'
‹tempenv-55e831397233f› ~ → py.test --version
This is pytest version 2.8.5, imported from /Users/andreas/.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/pytest.pyc
‹tempenv-55e831397233f› ~ → py.test test_foo.py
================================================= test session starts ==================================================
platform darwin -- Python 2.7.10, pytest-2.8.5, py-1.4.31, pluggy-0.3.1
rootdir: /Users/andreas, inifile:
collected 0 items / 1 errors

======================================================== ERRORS ========================================================
_____________________________________________ ERROR collecting test_foo.py _____________________________________________
.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/py/_code/code.py:412: in getrepr
    return fmt.repr_excinfo(self)
.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/py/_code/code.py:590: in repr_excinfo
    reprtraceback = self.repr_traceback(excinfo)
.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/py/_code/code.py:582: in repr_traceback
    reprentry = self.repr_traceback_entry(entry, einfo)
.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/py/_code/code.py:543: in repr_traceback_entry
    s = self.get_source(source, line_index, excinfo, short=short)
.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/py/_code/code.py:489: in get_source
    lines.extend(self.get_exconly(excinfo, indent=indent, markall=True))
.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/py/_code/code.py:496: in get_exconly
    exlines = excinfo.exconly(tryshort=True).split('\n')
.virtualenvs/tempenv-55e831397233f/lib/python2.7/site-packages/py/_code/code.py:376: in exconly
    text = ''.join(lines)
E   UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128)
=============================================== 1 error in 0.16 seconds ================================================
‹tempenv-55e831397233f› ~ → python test_foo.py
  File "test_foo.py", line 2
    assert 'ål', in 'a'
                   ^
SyntaxError: invalid syntax

The example is obviously not valid Python syntax and broken, but pytest should raise a SyntaxError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions