0

I have a problem where this is my project structure:

.
├── Resources/
├── src/
│   ├── __init__.py
│   ├── main.py
│   ├── utils/
│   │   ├── __init__.py
│   │   ├── util.py
│   │   └── otherUtil.py
│   └── calculations/
│       ├── __init__.py
│       └── financials.py
└── tests/
    ├── __init__.py
    └── test.py

My problem is that I can't reach the classes from the src/ folder from the tests, although the code in src/ can reach the Resources folder, through the first shown method.

I have tried:

  1. To append the home library path this way:

    enter image description here

    Here I used the from src import util after these lines, I even tried from .src import util.

  2. Then this way:

    enter image description here

    Here I used the from src import util after these lines, I even tried from .src import util.

  3. Than without the sys.path.append() with no use.

I have tried every combination I know, but for no use, and I don't want to install them as individual packages. Does someone have an idea, witch will solve my problem?

Clarification edit:

I don't want to put the tests in the source folder, i want to keep them separate.

kozter
  • 25
  • 5

1 Answers1

1

You can use this code found here:

# test.py
import sys
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, '/path/to/utils/')

import utils
oflint_
  • 297
  • 1
  • 8
  • Thanks, it worked with: `sys.path.insert(1, '.')`, but I don't understand, what is the difference between `sys.path.insert(1, '.')` and `sys.path.append('.')` ? – kozter Feb 02 '22 at 13:42
  • 1
    Not too much, it just ensures that the path is searched before other paths, including paths built into python. – oflint_ Feb 02 '22 at 13:45