py.test无法导入Pandas“TypeError:__name__必须设置为字符串对象”

时间:2016-04-26 23:25:36

标签: python pytest

[编辑] 此问题的最小示例是在pandas之前导入确定。当然是一个允许测试的测试库,如(1).should.equal(2)。我遇到的问题是,如果我从多个测试文件导入确定,它在运行我的测试时会出现相同的错误。

此代码

 import sure
 import pandas as pd

结果

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import pandas as pd
  File "C:\Users\lggodin\Documents\projects\vrops\dataapi\py27env\lib\site-packages\pandas\__in
it__.py", line 25, in <module>
    from pandas import hashtable, tslib, lib
  File "pandas/tslib.pyx", line 761, in init pandas.tslib (pandas\tslib.c:108072)
  File "pandas/tslib.pyx", line 724, in pandas.tslib._make_error_func (pandas\tslib.c:16177)
TypeError: __name__ must be set to a string object
(py27env)
Windows 8上的

python 2.7.11。

我正在使用py.test来测试使用Pandas的脚本。如果我运行py.test tests / unit / test_environment.py,测试运行成功。如果我只运行py.test或py.test tests / unit,它将失败,并且“TypeError: name 必须设置为字符串对象”

我的测试文件导入了环境导入pandas的环境,而pandas导入了tslib。这是它失败的地方。谁能告诉我这里发生了什么?我在virtualenv中使用python 2.7。我的所有主要代码都有效。只是测试文件失败了。 提前致谢。我粘贴了我的目录结构和不成功的py.test命令的示例。

$ 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

0 个答案:

没有答案