问题
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