py.测试无法导入Pandas“TypeError:\uuu name_u必须设置为字符串对象”

2024-09-28 21:51:38 发布

您现在位置:Python中文网/ 问答频道 /正文

[编辑] 这个问题的最小例子就是导入sure-before-pandas。Sure是一个测试库,它允许(1)这样的测试。应该相等(2) 一。我的问题是,如果我从多个测试文件导入sure,当我运行测试时,它会给出相同的错误。在

这个代码

 import sure
 import pandas as pd

结果

^{pr2}$

Windows8上的Python2.7.11。在

我正在使用py.测试测试一个使用Pandas的脚本。如果我跑了py.测试测试/单元/测试_环境.py测试运行成功。如果我跑了py.测试或者py.测试测试/单元失败,并显示“TypeError:名称必须设置为字符串对象”

我的测试文件导入环境.py它进口熊猫,熊猫进口tslib。这就是它失败的地方。有人能告诉我这里发生了什么事吗?我在virtualenv中使用python2.7。我所有的主要代码都能工作。只是测试文件失败了。 提前谢谢。我粘贴了我的目录结构和一个不成功的例子py.测试命令。在

$ py.test tests/unit
============================= test session starts =============================
platform win32 -- Python 2.7.11, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: C:\Users\lggodin\Documents\projects\vrops\dataapi\dataapi\tests\unit, inifile:
collected 8 items / 1 errors

tests\unit\test_client.py .........
tests\unit\test_propertymapper.py ...............

=================================== ERRORS ====================================
_____________________________ test_environment.py _____________________________
tests\unit\test_environment.py:1: in <module>
    from dataapi.dataapi.environment import Environment
dataapi\environment.py:1: in <module>
    import pandas as pd
..\py27env\lib\site-packages\pandas\__init__.py:25: in <module>
    from pandas import hashtable, tslib, lib
pandas/tslib.pyx:761: in init pandas.tslib (pandas\tslib.c:108072)
    ???
pandas/tslib.pyx:724: in pandas.tslib._make_error_func (pandas\tslib.c:16177)
    ???
E   TypeError: __name__ must be set to a string object
===================== 24 passed, 1 error in 1.07 seconds ======================
(py27env)
.
├── __init__.py
├── cert
│   └── intel.pem
├── console_setup.py
├── dataapi
│   ├── __init__.py
│   ├── client.py
│   ├── config.py
│   ├── environment.py
│   ├── propertymapper.py
│   ├── resource.py
│   └── resourceproperty.py
├── temp
│   └── certified_vm_properties.json
├── tests
│   ├── __init__.py
│   ├── integration
│   │   ├── __init__.py
│   │   ├── test_resource.py
│   │   └── test_resourceproperties.py
│   └── unit
│       ├── __init__.py
│       ├── test_client.py
│       ├── test_environment.py
│       └── test_propertymapper.py
├── Untitled.ipynb
├── vm_properties.json
└── vrops_api_testing.ipynb

Tags: 文件inpytestimportclientpandasenvironment