强制py.test使用已安装的模块版本

时间:2013-10-23 00:46:37

标签: pytest

我有一个混合的Python / C ++库,测试文件混合在同一目录的源文件中。布局看起来像

/home/irving/geode
  geode
    __init__.py
    vector
      __init__.py
      test_vector.py
      ...
    ...

不幸的是,由于缺少.so扩展模块,因此该库无法就地使用。 问题:即使从/home/irving/geode或子目录运行,我是否可以使py.test始终使用已安装的版本?

测试文件有from __future__ import absolute_import,如果直接作为脚本执行,则运行正常。例如,如果我这样做

cd geode/vector
./test_vector.py

import geode,找到已安装的版本。但是,如果我在geode/vector中运行py.test,它会找到geode的本地副本,然后就会死掉。

1 个答案:

答案 0 :(得分:8)

我认为你有两个选择:

  1. 运行py.test --pyargs geode.vector.test_vector使pytest将参数解释为导入路径,从中导出文件系统路径。这应该针对已安装的版本运行测试。

  2. 将测试移到tests目录中,而不包含__init__.py文件。这样,您需要pip install -e .就地工作,或者python setup.py installpy.test tests针对已安装的版本运行测试。

相关问题