| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
… while open NamedTemporaryFile defaults to delete-on-close, and on Windows the underlying file cannot be opened a second time while it is still open. MainModuleFileTest keeps self.file/self.file2 open in setUp(), but __main__.main() (via exec_module) and testFileNameModuleDuplication() both need to reopen them by path, which raises PermissionError on Windows. Fix by creating the temp files with delete=False, closing them right after writing, and removing them explicitly via addCleanup.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Sorry, something went wrong.
|
Verified on Windows 11 Home (build 26200), Python 3.13.13 and 3.14.7. The build matrix is macos + ubuntu only and the workflow here is still awaiting approval, so nothing has exercised this yet. python -m pytest fire/ -q at master 716bbc2: 2 failed, 259 passed. This PR alone: 1 failed, 260 passed, the remainder being testArgPassing (#679). Both PRs together: 261 passed, on both interpreters. Non-blocking note: the new comment says testFileNameModuleDuplication also needs these files reopened by path. That test only takes os.path.dirname(self.file.name) and opens a file it creates itself, so testFileNameFire is the only reopen. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes half of #693: MainModuleFileTest.testFileNameFire fails on Windows with PermissionError: [Errno 13] Permission denied.
Root cause: NamedTemporaryFile keeps the file open with its default delete=True behavior. On Windows the underlying file cannot be opened a second time while it's still open. setUp() keeps self.file open, but __main__.main() (via exec_module) has to reopen it by path to import it, which raises PermissionError on Windows only (POSIX allows reopening an already-open file).
Fix: create the temp files with delete=False, close them right after writing, and remove them explicitly with self.addCleanup(os.unlink, ...). This keeps cleanup guaranteed (even on test failure) while allowing the file to be reopened by path on Windows.
Verified locally on Windows 11 / Python 3.13.15:
The one remaining failure (testArgPassing, an unescaped-regex issue) is a separate bug already fixed by #679 — not touched here to keep this PR focused.
Full suite (pytest fire/) after this change: 1 failed, 260 passed (same single pre-existing failure, no new regressions).