diff --git a/nox/sessions.py b/nox/sessions.py index 396a09fc..d44f10b9 100644 --- a/nox/sessions.py +++ b/nox/sessions.py @@ -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) diff --git a/tests/test_sessions.py b/tests/test_sessions.py index e1e19eae..326133e5 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -18,6 +18,7 @@ import os import sys import tempfile +from pathlib import Path from unittest import mock import nox.command @@ -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()