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 waiting 20 seconds for mariadb-db:3306 mariadb-db:3306 is available after 0 seconds
Traceback (most recent call last):
  File "tests/", line 27, in <module>
    from django.test import TestCase, TransactionTestCase
  File "/tests/django/django/test/", line 3, in <module>
    from django.test.client import AsyncClient, AsyncRequestFactory, Client, RequestFactory
  File "/tests/django/django/test/", line 15, in <module>
    from django.core.handlers.asgi import ASGIRequest
  File "/tests/django/django/core/handlers/", 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/

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

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


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


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.


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