3
3
4
4
import py
5
5
import pytest
6
+ from six import PY2
6
7
7
8
import tox
8
9
from tox .interpreters import NoInterpreterInfo
@@ -770,21 +771,36 @@ def test_pythonpath_empty(self, newmocksession, monkeypatch, caplog):
770
771
assert "PYTHONPATH" not in pcalls [0 ].env
771
772
772
773
773
- def test_env_variables_added_to_pcall (tmpdir , mocksession , newconfig , monkeypatch ):
774
+ def test_env_variables_added_to_pcall (tmpdir , mocksession , newconfig , monkeypatch , tmp_path ):
774
775
monkeypatch .delenv ("PYTHONPATH" , raising = False )
775
776
pkg = tmpdir .ensure ("package.tar.gz" )
776
777
monkeypatch .setenv ("X123" , "123" )
777
778
monkeypatch .setenv ("YY" , "456" )
779
+ env_path = tmp_path / ".env"
780
+ env_file_content = "ENV_FILE_VAR = file_value"
781
+ env_path .write_text (env_file_content .decode () if PY2 else env_file_content )
782
+
778
783
config = newconfig (
779
784
[],
780
- """\
785
+ r"""
786
+ [base]
787
+ base_var = base_value
788
+
781
789
[testenv:python]
782
790
commands=python -V
783
791
passenv = x123
784
792
setenv =
785
793
ENV_VAR = value
794
+ ESCAPED_VAR = \{value\}
795
+ ESCAPED_VAR2 = \\{value\\}
796
+ BASE_VAR = {[base]base_var}
786
797
PYTHONPATH = value
787
- """ ,
798
+ TTY_VAR = {tty:ON_VALUE:OFF_VALUE}
799
+ COLON = {:}
800
+ REUSED_FILE_VAR = reused {env:ENV_FILE_VAR}
801
+ file| %s
802
+ """
803
+ % env_path ,
788
804
)
789
805
mocksession ._clearmocks ()
790
806
mocksession .new_config (config )
@@ -799,10 +815,18 @@ def test_env_variables_added_to_pcall(tmpdir, mocksession, newconfig, monkeypatc
799
815
assert env is not None
800
816
assert "ENV_VAR" in env
801
817
assert env ["ENV_VAR" ] == "value"
818
+ assert env ["ESCAPED_VAR" ] == "{value}"
819
+ assert env ["ESCAPED_VAR2" ] == r"\{value\}"
820
+ assert env ["COLON" ] == ";" if sys .platform == "win32" else ":"
821
+ assert env ["TTY_VAR" ] == "OFF_VALUE"
822
+ assert env ["ENV_FILE_VAR" ] == "file_value"
823
+ assert env ["REUSED_FILE_VAR" ] == "reused file_value"
824
+ assert env ["BASE_VAR" ] == "base_value"
802
825
assert env ["VIRTUAL_ENV" ] == str (venv .path )
803
826
assert env ["X123" ] == "123"
804
827
assert "PYTHONPATH" in env
805
828
assert env ["PYTHONPATH" ] == "value"
829
+
806
830
# all env variables are passed for installation
807
831
assert pcalls [0 ].env ["YY" ] == "456"
808
832
assert "YY" not in pcalls [1 ].env
0 commit comments