Force py.test to use installed version of module

喜你入骨 提交于 2019-12-07 11:33:41

问题


I have a mixed Python/C++ library with test files mixed in amongst source files in the same directories. The layout looks like

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

Unfortunately, the library is unusable in-place since it lacks .so extension modules. Question: Can I make py.test always use an installed version, even when run from /home/irving/geode or a subdirectory?

The test files have from __future__ import absolute_import, and run fine if executed directly as scripts. For example, if I do

cd geode/vector
./test_vector.py

which does import geode, it finds the installed version. However, if I run py.test in geode/vector, it finds the local copy of geode, and then dies.


回答1:


I think you have two options:

  1. run py.test --pyargs geode.vector.test_vector to make pytest interpretet the argument as an import path, deriving the file system path from it. This should run the test against the installed version.

  2. move the tests out into a tests directory without an __init__.py file. This way you need to pip install -e . to work in-place or can do python setup.py install and the py.test tests to run tests against the installed version.



来源:https://stackoverflow.com/questions/19530849/force-py-test-to-use-installed-version-of-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!