Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand environment variables when loading the noxfile from provided path #171

Merged
merged 2 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nox/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 15 additions & 0 deletions tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io
import json
import os
import platform
from unittest import mock

import pytest
Expand All @@ -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")
s0undt3ch marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down