How do I setup my Python Path so that pytest is able to find my Django ‘manage.py’ file?

I’m a college student currently working on a small Django web app project and I’m trying to get pytest up and running on my container.

When I try to run pytest, I receive an error


pytest-django could not find a Django project (no manage.py file could be found). You must explicitly add your Django project to the Python path to have it picked up.
make: *** [pytest] Error 1

I’m wondering how to fix this error so that pytest is able to find my manage.py which is inside another folder.

I’ve tried messing with the settings a bit but to no avail. Here’s what I tried in the manage.py file:

PROJECT_ROOT = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(PROJECT_ROOT, 'timetracker'))

This is my project structure:

timetracker/
  |---- accounts/
  |---- timetracker/
          |---- settings.py
  |---- conftest.py
  |---- manage.py

docker-compose.yml
Dockerfile
Makefile
pytest.ini
requirements.txt

Dockerfile:

ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code

COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

ENV DJANGO_SETTINGS_MODULE timetracker.settings

Any advice is appreciated!

Source: StackOverflow