nosetests默认编码是ascii,主程序是utf-8

nosetests default encoding is ascii, main program is utf-8

我所有的文件都以 #-*- coding: utf-8 -*-

开头

我的 virtualenv 设置为 python 3.5,virtualenv -p python3 venv

我的应用层次结构如下所示:

app/app/[file].py
        __init__.py

   /tests/test_[file].py
         /__init__.py
   main.py

python --version 为 3.5(venv 处于活动状态)

如果我 python main.py 并使用 sys.getdefaultencoding()print("é") 一切都很好,我得到:

> utf-8

> é

在 /tests 下,如果我 nosetests 我得到与 unicode 相关的错误,这是正常的,因为 sys.getdefaultencoding() 给我:

ascii

which pipwhich nosetestswhich python 都指向我的 venv。

当一切都不是时,为什么 nose 默认为 ascii?

pip freeze :

appdirs==1.4.2
beautifulsoup4==4.5.3
nose==1.3.7
packaging==16.8
pkg-resources==0.0.0
pyparsing==2.1.10
requests==2.13.0
six==1.10.0

编辑: 鼻子错误的一个例子是: TypeError: descriptor 'strip' requires a 'str' object but received a 'unicode'。我明白为什么会发生错误,我的误解是为什么只有鼻子在做。我在 Ubuntu 16.04.

Python 2.7 nose 我的系统默认安装有问题。

不在venv,我pip uninstall nose。然后我激活了使用 Python 3.5 的 virtualenv。在我的 venv 中,nose 只能从中选择 nosetests。成功了!

nosetests 似乎将 "global" nose 优先于特定的 nose。我还是不知道为什么会这样。