EDIT: here is an answer for an app/service
For testing within the same app/service I often use this pattern:
import inspect
import os
import sys
test_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
src_dir = os.path.join(test_dir, '..', 'app')
sys.path.append(src_dir)
from services.news_services import NewsServices
EDIT: Below is the original for packages but the question appears to relate to an app/service
Your best bet, and the one I use on a daily basis with packages that I maintain, is to install your own package and not use relative imports for this at all.
Your tests will find and import the package exactly as your users would.
Here is my install.sh
which you only have to do once; the trick is installing it in an "editable" fashion which, in this context, will cause anything importing it from the environment to find it exactly in your working structure with all your local changes:
#!/bin/bash
python3 -m venv env/
source env/bin/activate
pip install --editable "."
Then, within your tests:
from app.services.news_services import NewsServices
This is also described in this answer:
https://stackoverflow.com/a/6466139/351084