Search code examples
pythonpython-3.xcode-coveragetravis-cicodecov

Python custom module not found but already exists


I have created a separate file to hold some custom issue classes for my Python file and upon execution of the following command: coverage run test_syntax.py it prints out the following error as seen in this Travis CI build:

Traceback (most recent call last):
  File "test_syntax.py", line 9, in 
    from ros import main as s
  File "/home/travis/build/Richienb/ROS-Code/src/ros/main.py", line 57, in 
    from errors import ConversionError, WrongInput, UnexpectedError
ModuleNotFoundError: No module named 'errors'

You can find all of the code here

Also, I have already cd into the src directory.


Solution

  • You need a relative import like this (second one was needed on my machine to even get to the error you have posted):

    # in main.py
    from .errors import ...
    # ros.py
    from . import errors