0

I have a repository with the following directory structure:

repo_folder\
----src\
    ----__init__.py
    ----src1.py
    ----src2.py
    ----src3.py
----testing\
    ----specific_test.py
----requirements.txt

specific_test.py has on it's first lines:

import os
import sys

sys.path.insert(0, os.path.dirname(os.getcwd()))
import src.src1
import src.src2
import src.src3

# lots of asserts

When I run specific_test.py from within testing folder or from repo_folder folder it works, but only on my local machine.

The problem is that when I try to run this from my codeship account, it gives me an Import Error. The error looks like this:

  • ImportError while importing test module
  • ERROR collecting testing/specific_test.py
  • No module named src.src1
  • Make sure your test modules/packages have valid Python names.

Do you know what would the problem be?

Do you have suggestions for better alternatives?

Robert Lucian Chiriac
  • 686
  • 2
  • 15
  • 24
  • I did include an __ init __.py file in the testing folder. For the moment it gives me another error which refers to an invalid syntax on some imported module.Judging from this I think it works .. I'm still verifying. The syntax error must come from the fact that codeship deploys a python2.7 environment instead of python3. – Robert Lucian Chiriac Oct 12 '16 at 23:48

1 Answers1

0

This seems to be a pathing issue. What seems to be happening on your local machine is you insert into your path your CWD, which is most likely returning as repo_folder\. from there, you can import your src files via src.src1 because src is containe. On your codeship account, the cwd (current working directory) is not correct, thus is cannot find the src. part of src.src1. Check what the line sys.path.insert(0, os.path.dirname(os.getcwd())) returns, more importantly os.path.dirname(os.getcwd()) and verify that it is leading to repo_folder\

blurb
  • 600
  • 4
  • 20