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

Allow passing PathLike types to Session.chdir() #376

Merged
merged 1 commit into from
Jan 22, 2021
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
2 changes: 1 addition & 1 deletion nox/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def interactive(self) -> bool:
"""Returns True if Nox is being run in an interactive session or False otherwise."""
return not self._runner.global_config.non_interactive and sys.stdin.isatty()

def chdir(self, dir: str) -> None:
def chdir(self, dir: Union[str, os.PathLike]) -> None:
"""Change the current working directory."""
self.log("cd {}".format(dir))
os.chdir(dir)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import os
import sys
import tempfile
from pathlib import Path
from unittest import mock

import nox.command
Expand Down Expand Up @@ -151,6 +152,17 @@ def test_chdir(self, tmpdir):
assert os.getcwd() == cdto
os.chdir(current_cwd)

def test_chdir_pathlib(self, tmpdir):
cdto = str(tmpdir.join("cdbby").ensure(dir=True))
current_cwd = os.getcwd()

session, _ = self.make_session_and_runner()

session.chdir(Path(cdto))

assert os.getcwd() == cdto
os.chdir(current_cwd)

def test_run_bad_args(self):
session, _ = self.make_session_and_runner()

Expand Down