my tox setenv PYTHONPATH is not working but sh -c to forcefully set PYTHONPATH works

48 Views Asked by At
[testenv:migrations]
setenv =
    PYTHONPATH = {toxinidir}:{toxinidir}/src:{toxinidir}/tests
deps =
    -r requirements/py310-django42.txt
commands =
    echo PYTHONPATH={env:PYTHONPATH:}
    python tests/migration_script.py
    echo PYTHONPATH={env:PYTHONPATH:}
allowlist_externals =
    sh
    echo

when i do the above, and i try to print sys.path at the top of migration_script.py I see that the PYTHONPATH isn't set. Same thing with the echo PYTHONPATH=.

But when I do sh -c

setenv =
    PYTHONPATH = {toxinidir}:{toxinidir}/src:{toxinidir}/tests
deps =
    -r requirements/py310-django42.txt
commands_pre =
    sh -c 'export PYTHONPATH={toxinidir}:{toxinidir}/src:{toxinidir}/tests'
commands =
    sh -c 'PYTHONPATH={toxinidir}:{toxinidir}/src:{toxinidir}/tests python tests/migration_script.py'
    # python tests/migration_script.py
    echo PYTHONPATH={env:PYTHONPATH:}
allowlist_externals =
    sh
    echo

the sys.path at the top of migration_script.py works perfectly.

I am deeply confused why setenv doesn't work.

Please help me to understand why.

0

There are 0 best solutions below