Passing environment variables to tox

I have covered my blog with Django default tests, and now plan to add tox in order to use different versions of Python and Django. I am using docker and my relevant structure is like this:

project/app/tox.ini - Everything Django is inside /app/
project/.env.dev - Env vars for local development. It is handled by docker while running the site.

My current tox.ini:

[tox]
envlist =
    py310-django50
    py310-django51
    py312-django50
    py312-django51
skipsdist = True
skip_missing_interpreters = True

[testenv]
deps =
    django50: Django==5.0.*
    django51: Django==5.1.*
    sentry_sdk
setenv =
    DJANGO_SETTINGS_MODULE = django_project.settings
    DEBUG = False
commands =
    python manage.py test

The question is, how can I pass my .env.dev to the tox.ini? Copy-pasting defeats the purpose. Because I am experimenting with tox for the first time, what is the standard way?

I’m not a tox expert but I don’t think that’s possible with tox alone.

There is this plugin though, but I haven’t tried it GitHub - hypothesis/tox-envfile: A tox plugin that loads envvars from env files into your tox envs

1 Like