带有'£'符号的pytest unicode语法错误

时间:2016-08-05 19:57:46

标签: python unit-testing testing pytest python-3.5

我有一个测试文件:test_pytest.py

def test_pytest():
    s = '£'
    assert True

使用pytest,我这样运行:python -m pytest test_pytest.py

结果:

> python -m pytest test_pytest.py
============================= test session starts =============================
platform win32 -- Python 3.5.2, pytest-2.9.2, py-1.4.31, pluggy-0.3.1
rootdir: c:\temp, inifile:
collected 0 items / 1 errors

=================================== ERRORS ====================================
_______________________ ERROR collecting test_pytest.py _______________________
c:\projects\aio-rpc\venv\lib\site-packages\_pytest\python.py:611: in _importtestmodule
    mod = self.fspath.pyimport(ensuresyspath=importmode)
c:\projects\aio-rpc\venv\lib\site-packages\py\_path\local.py:650: in pyimport
    __import__(modname)
E     File "c:\temp\test_pytest.py", line 3
E   SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xa3 in position 0: invalid start byte
=========================== 1 error in 0.07 seconds ===========================

是什么给出了?

请注意,评论s='£'可以让测试通过

1 个答案:

答案 0 :(得分:0)

愚蠢的我,我的Vim用latin1编码而不是utf-8保存文件。将文件的编码更改为utf-8修复了问题。