You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add CliRunner.set_filesystem() to use a specific working directory #3123
The CliRunner.isolated_filesystem is find for testing tools that have no preconceived notion of what the directory structure should look like, or what files must be present. While it's true that you can provide a parent directory to isolated_filesystem(), it will still create a brand new empty directory and operate within it.
CliRunner.set_filesystem() operates in the same way, except that you provide it with a pre-existing directory to operate in.
Suppose your tool requires that it be run in a directory named 'library' containing certain data files. Your test might look start like this:
With isolated_filesystem(), running your command in this directory will not work, because it will run not in the library directory just created, but in a sub-directory of that one.
I'm not clear why this is needed. I can't think of a good reason for a command to require being run in a directory with a certain name. That said, if you need it for some reason, create it in the isolated context, then cd further.
Nowadays you can also use pytest directly for this, or use with tempfile.TemporaryDirectory(). I don't think we'd add isolated_filesystem today, I think it was added before Python 3 and pytest were in common use.
In that case, perhaps consider marking isolated_filesystem() as deprecated. It seemed to me to be the way things should be done, and without knowing otherwise I assumed that it did more than just os.chdir().
changed the title [-]Add CliRunner.set_filesystem() to use a specific working directory[/-][+]Add `CliRunner.set_filesystem()` to use a specific working directory[/+]on May 23, 2026
Activity
davidism commentedon Oct 22, 2025
I'm not clear why this is needed. I can't think of a good reason for a command to require being run in a directory with a certain name. That said, if you need it for some reason, create it in the isolated context, then cd further.
Nowadays you can also use pytest directly for this, or use
with tempfile.TemporaryDirectory(). I don't think we'd addisolated_filesystemtoday, I think it was added before Python 3 and pytest were in common use.bphunter1972 commentedon Oct 22, 2025
In that case, perhaps consider marking
isolated_filesystem()as deprecated. It seemed to me to be the way things should be done, and without knowing otherwise I assumed that it did more than justos.chdir().kdeldycke commentedon Oct 25, 2025
I am in favor of deprecating
isolated_filesystem()and simplify code. Maybe for Click 9.x.Pytest is maintained and wide-spread. We can simply add a snippet in the documentation to explain how to use the
CliRunnerwith vanilla Pytest.[-]Add CliRunner.set_filesystem() to use a specific working directory[/-][+]Add `CliRunner.set_filesystem()` to use a specific working directory[/+]kdeldycke commentedon May 23, 2026
This discussion is related to #3501