0

I am trying to importing

fethcer . py file from 

src/fetcher/entrypoints/fethcer.py

to tests/steps/step_impl.py file

how can i import that?

...src.fetcher.entrypoints.fetcher import *

but it's giving me error

from ...src.fetcher.entrypoints.fetcher import * ImportError: attempted relative import with no known parent package

then what is the way?

dependency graph is -

 .
    ├── fetcher.db
    ├── README.MD
    ├── src
    │   └── fetcher
    │       ├── entrypoints
    │       │   ├── fetcher.py
    │       │   ├── __init__.py
    │       │   └── __pycache__
    │       │       
    │       │   
    │       ├── __init__.py
    │       └── __pycache__
    │           
    └── tests
        ├── acceptance
        │   └── fetch_relevant_instrument_list.feature
        ├── environment.py
        └── steps
            └── steps_impl.py
Riku
  • 5
  • 4

1 Answers1

0

This should work:

steps_impl will have following line:

import sys
sys.path.insert(1, r'path/to/the/application/')
from src.fetcher.fetcher import func1

I tried to recreate your folder structure:

D:.
├───src
│   ├───fetcher
│   │   └───__pycache__
│   │   └───__init__.py
│   │   └───fetcher.py
│   ├───__pycache__
│   └───__init__.py
└───tests
    ├───acceptance
    └───steps
        └───steps_impl.py

I refered this Question.

Vishal R
  • 1,279
  • 1
  • 21
  • 27
  • Where i need to add those lines ? inside fetcher.py? or steps_impl.py? or __init__.py? or i have to install it by creating a setup.py file?..... I am trying to importing fecher.py inside steps_impl.py , so shall i need tho add those lines in fetcher.py file? and there won't be 1 there needs to be 2 or 3 – Riku Feb 05 '22 at 15:31
  • and it also giving me error no module name src – Riku Feb 05 '22 at 15:35
  • add _ _ init _ _.py in src folder as well – Vishal R Feb 05 '22 at 15:47