使用 Travis-CI 测试时如何将 tests/ 目录添加到 PYTHONPATH?

How to add tests/ directory to PYTHONPATH when testing with Travis-CI?

我的包结构:

foop
|___foop
|   |___foo.py
|
|___tests
    |__test_foo.py
    |__test_helper.py

test_foo.py 导入 foo 和 test_helper:

import foo
import test_helper

问题是 tests 不在 $PYTHONPATH 中,所以 import test_helper 引发 ImportError

我是 Travis 的新手-CI。谁能告诉我如何解决这个导入错误?

travis env 变量就是您要找的。

尝试将此 yml 添加到您的 .travis.yml:

env: PYTHONPATH=$PYTHONPATH:$TRAVIS_BUILD_DIR/tests:$TRAVIS_BUILD_DIR/foop