Skip to content

Commit 6617b49

Browse files
author
Release Manager
committed
gh-35999: Run pytest for src tree if no filename is given <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> This fixes the failure seen, for example, https://github.com/sagemath/sage/actions/runs/5678761729/job/15389749593 ?pr=35991 Note that the last failure message ``` local/var/lib/sage/venv-python3.8/lib/python3.8/site- packages/matplotlib/tests/__init__.py:6: in <module> raise IOError( E OSError: The baseline image directory does not exist. This is most likely because the test data is not installed. You may need to install matplotlib from source to get the test data. =========================== short test summary info ============================ ERROR - OSError: The baseline image directory does not exist. This is most likely because the test data is not installed. You may need to install matplotlib from source to get the test data. !!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!! ============================== 1 error in 12.78s =============================== Error: Process completed with exit code 2. ``` This is not a fault of matplotlib! The fault lies on our pytest, which blindly runs all tests found in the directory tree under the root dir. (matplotlib test files are supposed to run in a development install, where the baseline image directory exists, but our install (SPKG) of matplotlib is not a development install, and hence there's no baseline image directory.) So we need to stop pytest from running blind. The failure in the incremental test workflow results from an error in `sage-runtests`. The relevant lines are ```python exit_code_pytest = 0 import pytest pytest_options = [] if args.verbose: pytest_options.append("-v") # #31924: Do not run pytest on individual Python files unless # they match the pytest file pattern. However, pass names # of directories. We use 'not os.path.isfile(f)' for this so that # we do not silently hide typos. filenames = [f for f in args.filenames if f.endswith("_test.py") or not os.path.isfile(f)] if filenames or not args.filenames: # <------------------------------------ faulty line! print(f"Running pytest on {filenames} with options {pytest_options}") exit_code_pytest = pytest.main(filenames + pytest_options) if exit_code_pytest == 5: # Exit code 5 means there were no test files, pass in this case exit_code_pytest = 0 ``` Look at the faulty line. The condition test allows pytest run without explicit filenames. This results in running pytest for all test files found under the (sage) root dir. Hence pytest attempts to run tests in matplotlib in `local/var/lib/sage/venv-python3.11/lib/python3.11/site- packages/matplotlib/tests`. The branch of this PR fixes the problem. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35999 Reported by: Kwankyu Lee Reviewer(s): Kwankyu Lee, Matthias Köppe, Tobias Diez
2 parents 0ad2117 + e17f1de commit 6617b49

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/bin/sage-runtests

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,18 @@ if __name__ == "__main__":
175175
pytest_options = []
176176
if args.verbose:
177177
pytest_options.append("-v")
178-
# #31924: Do not run pytest on individual Python files unless
179-
# they match the pytest file pattern. However, pass names
180-
# of directories. We use 'not os.path.isfile(f)' for this so that
181-
# we do not silently hide typos.
182-
filenames = [f for f in args.filenames
183-
if f.endswith("_test.py") or not os.path.isfile(f)]
184-
if filenames or not args.filenames:
178+
179+
# #35999: no filename in arguments defaults to "src"
180+
if not args.filenames:
181+
filenames = [SAGE_SRC]
182+
else:
183+
# #31924: Do not run pytest on individual Python files unless
184+
# they match the pytest file pattern. However, pass names
185+
# of directories. We use 'not os.path.isfile(f)' for this so that
186+
# we do not silently hide typos.
187+
filenames = [f for f in args.filenames
188+
if f.endswith("_test.py") or not os.path.isfile(f)]
189+
if filenames:
185190
print(f"Running pytest on {filenames} with options {pytest_options}")
186191
exit_code_pytest = pytest.main(filenames + pytest_options)
187192
if exit_code_pytest == 5:

0 commit comments

Comments
 (0)