How to set the environment variable in tox?

You can make test envs inherit values from [base], according to the docs.

[tox]
envlist =
    test1
    test2

[base]
setenv =
    XYZ = 123

[testenv:test1]
deps=pytest
commands=py.test
setenv =
    {[base]setenv}

[testenv:test2]
deps=pytest
commands=py.test
setenv =
    {[base]setenv}

setenv must be in [testenv]:

[tox]
envlist = py35

[testenv]
deps=pytest
commands=py.test
setenv =
    XYZ = 123

You can pass all the einvornment variables to the tests using:

[testenv]
passenv = XYZ