Skip to content

Report an error when run_script is given a directory of no size - #1853

Merged
tleonhardt merged 2 commits into
mainfrom
fix-run-script-directory
Dec 1, 2026
Merged

tleonhardt merged 2 commits into
mainfrom
fix-run-script-directory

Conversation

@tleonhardt

Copy link
Copy Markdown
Member

run_script given a directory which reports a size of zero printed nothing and set last_result to True. It now reports an error.

The cause

do_run_script takes a file of size zero for an empty script, which is not an error, and returns. It found a directory to be one only later, when opening it failed. A directory can report a size of zero too, and then the early return is taken.

How it showed

test_run_script_with_invalid_file runs run_script on the directory the tests are in. On #1849 it failed on Windows with Python 3.12 and 3.14, with no error printed for the directory, and passed in the other four Windows jobs of the same run. The two failed jobs passed when run again on the same commit (run 46730357548). None of the 29 failed runs of the Tests workflow before it, back to mid-November, failed in this test.

The code in question is the same on main, so the same failure can happen here.

Not known: why Windows reported a size of zero for that directory in two jobs and not in the others. The fix does not depend on the answer.

The change

  • run_script looks for a directory before anything else and reports Problem accessing script from '<path>': it is a directory. The text after the colon used to be the operating system's error for opening a directory, which on POSIX is [Errno 21] Is a directory.
  • A new test, test_run_script_with_directory_of_no_size, makes os.path.getsize() return zero and runs run_script on a directory. Before the fix it fails with the same IndexError at the same assertion as in CI; after it, it passes.
  • A changelog entry under 4.4.5.

Evidence

On macOS, make check, make test (3,212 passed, 3 skipped) and make docs-test pass. Not run on Windows other than by CI on this PR.

run_script takes a file of size zero for an empty script, which is not an error, and found a directory to be one only when opening it failed. A directory can report a size of zero too. Then run_script printed nothing and set last_result to True.

This showed in CI as test_run_script_with_invalid_file failing on Windows with Python 3.12 and 3.14 and passing in the other four Windows jobs, and in the same two when they were run again: Windows reported that size for the tests directory in some jobs and not in others. Why it did is not known. run_script now looks for a directory first, so its answer no longer depends on the size. The message for a directory says that it is one, where it used to give the operating system's error for opening it.
@codecov

codecov Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.76%. Comparing base (bb0e35e) to head (2c6d58a).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1853   +/-   ##
=======================================
  Coverage   99.76%   99.76%           
=======================================
  Files          23       23           
  Lines        6767     6770    +3     
=======================================
+ Hits         6751     6754    +3     
  Misses         16       16           
Flag Coverage Δ
unittests 99.76% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Found in review. Where the temporary directory's path has a space, the command was parsed as several arguments, and argparse printed its usage before run_script looked at the directory. The path is now quoted, so the test passes or fails for what it tests wherever it runs.
@tleonhardt
tleonhardt merged commit aa32960 into main Dec 1, 2026
28 checks passed
@tleonhardt
tleonhardt deleted the fix-run-script-directory branch December 1, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant