Running django tests in Mariadb with venv or other container

Hi All,

I am contributing to Django and would like to run django tests in Mariadb. I have installed django-docker-box and have run python environment. But when I run tests I got error

(venv) [ (main) 18:39:41 ~/development/django_dev/django-docker-box]$ PYTHON_VERSION=3.8 MARIADB_VERSION=10.7 docker-compose pull mariadb
Pulling mariadb ... done
(venv) [ (main) 18:47:41 ~/development/django_dev/django-docker-box]$ PYTHON_VERSION=3.8 MARIADB_VERSION=10.7 docker-compose run mariadb
Creating django-docker-box_mariadb_run ... done
wait-for-it.sh: waiting 20 seconds for mariadb-db:3306
wait-for-it.sh: mariadb-db:3306 is available after 0 seconds
Traceback (most recent call last):
  File "tests/runtests.py", line 27, in <module>
    from django.test import TestCase, TransactionTestCase
  File "/tests/django/django/test/__init__.py", line 3, in <module>
    from django.test.client import AsyncClient, AsyncRequestFactory, Client, RequestFactory
  File "/tests/django/django/test/client.py", line 15, in <module>
    from django.core.handlers.asgi import ASGIRequest
  File "/tests/django/django/core/handlers/asgi.py", line 6, in <module>
    from asgiref.sync import ThreadSensitiveContext, sync_to_async
ImportError: cannot import name 'ThreadSensitiveContext' from 'asgiref.sync' (/usr/local/lib/python3.8/site-packages/asgiref/sync.py)
ERROR: 1

in env I have got asgiref v.3.4.1 installed.
The docker is using my system python. Correct python is

(venv) [ (main) 18:49:06 ~/development/django_dev/django-docker-box]$ which python
/home/coco/development/django_dev/venv/bin/python

How to tell the container to use python and libs from virtual env?

Or other solution is separate test container with django, python and db client that connect to db container. But how to do that? From my point of view it would be better solution.

I have prepared Docker file

# syntax=docker/dockerfile:1
FROM python:3.10-slim

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN apt-get update \
    && apt-get install --no-install-recommends -y \
          libmemcached-dev \
          build-essential \
          libsqlite3-mod-spatialite binutils libproj-dev gdal-bin libgdal28 libgeoip1 \
          default-libmysqlclient-dev default-mysql-client \
          libpq-dev \
          unzip libaio1 \
          libenchant-2-2 \
          gettext \
          wget \
          git \
    && apt-get clean

WORKDIR /code

RUN pip install --upgrade pip
RUN pip install mysqlclient

ADD django-repo /code/django-repo
RUN pip install -e /code/django-repo

Tried different docker-compose configuration but haven’t achieved the goal.

Thanks,
Albert

Issue solved. Configuration is correct, removed all containers and images downloaded, and went through build process again solved the issue.