diff --git a/nox/tasks.py b/nox/tasks.py index 1533f018..f392f65c 100644 --- a/nox/tasks.py +++ b/nox/tasks.py @@ -41,7 +41,10 @@ def load_nox_module(global_config): # Save the absolute path to the Noxfile. # This will inoculate it if nox changes paths because of an implicit # or explicit chdir (like the one below). - global_config.noxfile = os.path.realpath(global_config.noxfile) + global_config.noxfile = os.path.realpath( + # Be sure to expand variables + os.path.expandvars(global_config.noxfile) + ) # Move to the path where the Noxfile is. # This will ensure that the Noxfile's path is on sys.path, and that diff --git a/tests/test_sessions.py b/tests/test_sessions.py index 58dcd538..04194014 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -400,7 +400,7 @@ def test__create_venv_options(self, create): create.assert_called_once_with(runner.venv) assert isinstance(runner.venv, nox.virtualenv.VirtualEnv) - assert runner.venv.interpreter is "coolpython" + assert runner.venv.interpreter == "coolpython" assert runner.venv.reuse_existing is True def make_runner_with_mock_venv(self): diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 75afd422..50059569 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -17,6 +17,7 @@ import io import json import os +import platform from unittest import mock import pytest @@ -43,6 +44,20 @@ def test_load_nox_module(): assert noxfile_module.SIGIL == "123" +def test_load_nox_module_expandvars(): + # Assert that variables are expanded when looking up the path to the noxfile + # This is particular importand in Windows when one needs to use variables like + # %TEMP% to point to the noxfile.py + with mock.patch.dict(os.environ, {"RESOURCES_PATH": RESOURCES}): + if platform.system().lower().startswith("win"): + config = argparse.Namespace(noxfile="%RESOURCES_PATH%/noxfile.py") + else: + config = argparse.Namespace(noxfile="${RESOURCES_PATH}/noxfile.py") + noxfile_module = tasks.load_nox_module(config) + assert noxfile_module.__file__ == os.path.join(RESOURCES, "noxfile.py") + assert noxfile_module.SIGIL == "123" + + def test_load_nox_module_not_found(): config = argparse.Namespace(noxfile="bogus.py") assert tasks.load_nox_module(config) == 2 diff --git a/tests/test_virtualenv.py b/tests/test_virtualenv.py index 525b0cfa..4527cb88 100644 --- a/tests/test_virtualenv.py +++ b/tests/test_virtualenv.py @@ -54,7 +54,7 @@ def test_constructor_defaults(make_one): def test_constructor_explicit(make_one): venv, _ = make_one(interpreter="python3.5", reuse_existing=True) assert venv.location - assert venv.interpreter is "python3.5" + assert venv.interpreter == "python3.5" assert venv.reuse_existing is True