Reputation: 49
This is my first time using Travis and "test" in general. I created a few test and now I want to add them to Travis but I'm having trouble with PATHs.
Here is what I have:
sheetmaker/
html_builder.py
constants.py
sheetmaker.py
tests/
test_html_builder.py
data/
test_html_constants.py
I manage to run test_html_builder.py
and test are working in my pc. In short this is how I'm importing stuff in test_html_builder.py
sys.path.insert(0, os.path.abspath('..'))
from sheetmaker import html_builder
from data import test_html_constants
This works locally but Travis CI says:
What is the right way to import stuff? Here is the github project for more details: github project!
Thanks in advance.
Upvotes: 1
Views: 1048
Reputation: 117
@cosme12 I didn't try your solution, but I was able to fix the path issue by explicitly declaring the PYTHONPATH in the .travis.yml
sample .travis.yml:
sudo: false
language: python
python:
- "3.6"
install:
- export PYTHONPATH=$PYTHONPATH:$(pwd)/src/thermo
- python3 setup.py install
script:
- pytest -s
Just manually add the path that's missing to the .travis.yml and travis should work.
I like this solution because you don't need to alter your code, just the travis config file.
Upvotes: 2
Reputation: 49
After tons of research, I started printing print(sys.path)
to find out where "I was working". From there I created an exception handler
try:
sys.path.insert(0, os.path.abspath('..')) #Works for local
from sheetmaker import html_builder
from data import test_html_constants
except:
sys.path.insert(0, os.path.abspath('.')) #Works for Travis CI
from sheetmaker import html_builder
from data import test_html_constants
Is this the right way to import modules? No idea, but it works.
Upvotes: 2