Skip to content

Commit

Permalink
Export session name in envvar NOX_CURRENT_SESSION (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbarrett committed Aug 4, 2022
1 parent 4e47da4 commit 5eecc52
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ def execute(self) -> Result:
with cwd:
self._create_venv()
session = Session(self)
session.env["NOX_CURRENT_SESSION"] = session.name
self.func(session)

# Nothing went wrong; return a success.
Expand Down
19 changes: 19 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,8 @@ def test__create_venv_unexpected_venv_backend(self):
def make_runner_with_mock_venv(self):
runner = self.make_runner()
runner._create_venv = mock.Mock()
runner.venv = mock.create_autospec(nox.virtualenv.VirtualEnv)
runner.venv.env = {}
return runner

def test_execute_noop_success(self, caplog):
Expand Down Expand Up @@ -1017,6 +1019,23 @@ def func(session):

assert result.status == nox.sessions.Status.FAILED

def test_execute_check_env(self):
runner = self.make_runner_with_mock_venv()

def func(session):
session.run(
sys.executable,
"-c",
'import os; raise SystemExit(0 if os.environ["NOX_CURRENT_SESSION"] =='
f" {session.name!r} else 0)",
)

runner.func = func

result = runner.execute()

assert result


class TestResult:
def test_init(self):
Expand Down

0 comments on commit 5eecc52

Please sign in to comment.