0

I'm trying to write tests for my project in a different folder named tests like most opensrc projects. But I always get module not found

This is how my project looks:

.
├── __init__.py
├── src
│   ├── func.py
│   └── __init___.py
└── tests
    ├── __init__.py
    └── test_func.py

Here is my code in test_func.py

from src.func import function

function()

When i run this in pycharm, it runs flawlessly. But when i try editors like vscode or even a normal terminal i get:

ModuleNotFoundError: No module named 'src'

I tried to execute test_func.py from the project directory as well as other subfolders. I just get that error every time. I'm sure this is not good behavior since my code cant run on my friends computer.

How do i fix it? I've read and seen a lot of import tutorials but could not find a way to fix the problem

Any help is appreciated thanks

default-303
  • 361
  • 1
  • 4
  • 15
  • Does [this](https://stackoverflow.com/questions/43728431/relative-imports-modulenotfounderror-no-module-named-x) answer to your question ? – ApuCoder Feb 21 '22 at 11:10
  • @ApuCoder sadly no, I'm sure altering `sys.path` will make it work but I feel like its not a good solution. – default-303 Feb 21 '22 at 11:32

0 Answers0