TravisCI with pytest and numpy.load(): File not found

…衆ロ難τιáo~ 提交于 2019-12-11 11:01:49

问题


I have the following in my tests/conftest.py file, used to load a numpy array as a fixture object for tests that are run by pytest:

@pytest.fixture(scope="module")
def my_fixture():

    return np.load(os.path.join(os.getcwd(), "fixture", "example.npy")

The file projectname/tests/fixture/example.npy is present.

This runs fine when I launch my tests from PyCharm, but when the tests run on TravisCI I get a file not found error, with the file path shown as missing the tests directory, i.e. it should be looking for the file as /home/travis/build/username/projectname/tests/fixture/example.npy but instead it's looking for the file as /home/travis/build/username/projectname/fixture/example.npy, as if it's starting from the project's main directory and not the tests subdirectory which is the assumed relative location.

The projectname/tests directory contains all the test files, and the *.npy fixture files are in projectname/tests/fixture.

Can I make a setting in the .travis.yml file to configure pytest so it knows how to find the *.npy files as I'm expecting when making the call to numpy.load? Or is this instead somehow related to pytest's rootdir setting which appears to be behaving differently on TravisCI than when I run the tests from within PyCharm?

来源:https://stackoverflow.com/questions/53719350/travisci-with-pytest-and-numpy-load-file-not-found

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