Repository navigation
isolated_filesystem() is not thread safe #3501
Description
Activity
- addedtest runnerCliRunner and Click's test utilities featureCliRunner and Click's test utilities feature
on May 22, 2026 Reminder that we should probably deprecate
isolated_filesystem, there's a discussion about that somewhere around here.Reacted by Kevin DeldyckeReminder that we should probably deprecate
isolated_filesystem, there's a discussion about that somewhere around here.Found it at: #3123 (comment)
BTW it looks like the original proposal by @bphunter1972 in #3123 of a
runner.set_filesystemcontext manager seems to address the thread-safety as each runner will produce its artefacts and assets in its own directory on CLI invokation.To clarify:
tox parallelis for running multiple interpreter environments in parallel. It is not the same as running the tests in one interpreter in parallel. I've never had an expectation that tests should be thread safe. If you were to use pytest-xdist it would use processes to run subsets of tests serially.For free threading, I'd expect test runners (unittest, pytest, etc) to provide a way to manage threads and locks for unsafe tests. That's getting way outside the scope of Click and this function.
I can't tell what the comment from @Rowlando13 was saying, given the above. There's also no more information in this issue. We also all agree this function should be deprecated. Therefore I think this issue should be closed.
My comment was specifically that I thought that isolated_filesystem creates a folder and then makes expectations about what is in that folder, so if there are multiple isolated_filesystem calls in a test suite and the tests are running in parallel there is a race condition between those tests.
I agree with deprecating isolated_filesystem. Better to show a pytest example.
I closed the related issue. I see why this should be separate and stay open if only to clarify a bit. Even with separate interpreters, I don't see how tox -p is safe(since each suite at various times make random folders, does stuff, and looks in them) unless tox runs the interpreters from different base folders.
isolated_filesystemcallstempfile.mkdtemp, so every invocation is a separate folder. It does callos.chdir, which isn't thread safe, but serializing that should be left to the test framework, not us.tox pdoes create a separate base dir for every environment.Thanks for explaining. Closing issue.
Given #3676 , I guess the milestone change to 9.0.0 is just the blast radius of the recent
main<->stabledance. So I retarget this to 8.5.0 unless an explicit decision is made.I agree with deprecating isolated_filesystem. Better to show a pytest example.
I created a dedicated issue at #3700
- added a commit that references this issue
on Jul 17, 2026 - linked a pull request that will close this issueBad attempt: Deprecate `isolated_filesystem` and document its limits #3701
on Jul 17, 2026 - removed a link to a pull requestBad attempt: Deprecate `isolated_filesystem` and document its limits #3701
on Jul 17, 2026 - linked a pull request that will close this issueDeprecate `isolated_filesystem` and document its limits #3704
on Jul 17, 2026 - added 2 commits that reference this issue
on Jul 17, 2026 - locked as resolved and limited conversation to collaborators
on Aug 1, 2026
This is a follow-up on #2899, to cover for @Rowlando13's concerns that
isolated_filesystem()is not thread safe: #2899 (comment)