使用模拟库,python单元测试问题的异常

时间:2018-02-01 08:06:26

标签: python unit-testing mocking

  • Windows 7 Professional(64位)
  • Python 2.7.14(2.7.14150 64 bit)
  • mock 2.0.0

当我从命令提示符(作为管理员)运行python -c "import mock"时,它会产生异常:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python27\lib\site-packages\mock\__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "C:\Python27\lib\site-packages\mock\mock.py", line 71, in <module>
    _v = VersionInfo('mock').semantic_version()
  File "C:\Python27\lib\site-packages\pbr\version.py", line 461, in semantic_version
    self._semantic = self._get_version_from_pkg_resources()
  File "C:\Python27\lib\site-packages\pbr\version.py", line 448, in _get_version_from_pkg_resources
    result_string = packaging.get_version(self.package)
  File "C:\Python27\lib\site-packages\pbr\packaging.py", line 755, in get_version
    name=package_name))
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given t
o pbr.version.VersionInfo. Project name mock was given, but was not able to be found.

2 个答案:

答案 0 :(得分:1)

答案在最后的异常消息中:Versioning for this project requires either an sdist tarball, or access to an upstream git repository. It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo. Project name mock was given, but was not able to be found.

这似乎是pbr包的问题。您是否尝试重新安装或删除它以测试是否可以解决此问题(这表明您需要在pbr上进行密集)?

答案 1 :(得分:0)

我有同样的问题,在我的情况下更新setuptools是修复。 我在这里找到了这个建议: https://github.com/testing-cabal/mock/issues/314

在更新之前,我有setuptools 0.6c11,我已经更新到最新的39.2.0。

pip install --upgrade setuptools

或实际上在我的情况下我必须在本地下载和安装,因为生产服务器没有连接到互联网:

pip download setuptools

pip install setuptools-39.2.0-py2.py3-none-any.whl