Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest: Improve doctest integration #39206

Merged
merged 3 commits into from
Jan 4, 2025
Merged

Conversation

tobiasdiez
Copy link
Contributor

With these changes it should now be possible to run doctests via pytest: e.g. pytest --doctest src/sage/manifolds.

There are still a lot of errors since pytests handles a few things differently (most notable it doesn't isolate tests from each other). These issues will be fixed in follow-ups.

I've also moved the pytest config from src to the root for better vscode integration. Added also a bit of typing information in the doctest framework.

📝 Checklist

  • The title is concise and informative.
  • 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 and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Dec 27, 2024

Documentation preview for this PR (built with commit 5863a98; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@tobiasdiez tobiasdiez requested a review from dimpase December 29, 2024 15:02
@dimpase
Copy link
Member

dimpase commented Dec 29, 2024

What exactly "better vscode integration" does mean here? That's something that ought to be documented, eventually,
At least, please explain here how to run tests from vscode.

Copy link
Member

@dimpase dimpase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm otherwise

@tobiasdiez
Copy link
Contributor Author

What exactly "better vscode integration" does mean here? That's something that ought to be documented, eventually, At least, please explain here how to run tests from vscode.

Tests show up now in the test explorer and can be run in the "usual" way: https://code.visualstudio.com/docs/python/testing

Thanks for the review!

@vbraun
Copy link
Member

vbraun commented Jan 1, 2025

I'm getting

make --no-print-directory sagemath_doc_html-SAGE_DOCS-no-deps
[sagemath_doc_html-none] Setting up build directory /home/release/Sage/local/var/tmp/sage/build/sagemath_doc_html-none
[sagemath_doc_html-none] Host system: Linux zen 6.12.4-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Dec  9 20:01:35 UTC 2024 x86_64 GNU/Linux
[sagemath_doc_html-none] C compiler: gcc, Using built-in specs., COLLECT_GCC=gcc, COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/14/lto-wrapper, OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa, OFFLOAD_TARGET_DEFAULT=1, Target: x86_64-redhat-linux, Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-14.2.1-build/gcc-14.2.1-20240912/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1, Thread model: posix, Supported LTO compression algorithms: zlib zstd, gcc version 14.2.1 20240912 (Red Hat 14.2.1-3) (GCC)
[sagemath_doc_html-none] Warning: No files to uninstall for 'sagemath_doc_html'
[sagemath_doc_html-none] Removing stamp file /home/release/Sage/local/var/lib/sage/installed/sagemath_doc_html-none
[sagemath_doc_html-none] [spkg-install] mkdir -p en/reference/repl
[sagemath_doc_html-none] [spkg-install] sage -advanced > en/reference/repl/options.txt
[sagemath_doc_html-none] [spkg-install] Traceback (most recent call last):
[sagemath_doc_html-none] [spkg-install]   File "<frozen runpy>", line 198, in _run_module_as_main
[sagemath_doc_html-none] [spkg-install]   File "<frozen runpy>", line 88, in _run_code
[sagemath_doc_html-none] [spkg-install]   File "/home/release/Sage/src/sage_docbuild/__main__.py", line 82, in <module>
[sagemath_doc_html-none] [spkg-install]     from .builders import DocBuilder, ReferenceBuilder, get_builder, get_documents
[sagemath_doc_html-none] [spkg-install]   File "/home/release/Sage/src/sage_docbuild/builders.py", line 76, in <module>
[sagemath_doc_html-none] [spkg-install]     import sage.all
[sagemath_doc_html-none] [spkg-install]   File "/home/release/Sage/src/sage/all.py", line 63, in <module>
[sagemath_doc_html-none] [spkg-install]     from sage.all__sagemath_repl import *
[sagemath_doc_html-none] [spkg-install]   File "/home/release/Sage/src/sage/all__sagemath_repl.py", line 113, in <module>
[sagemath_doc_html-none] [spkg-install]     from sage.repl.all import *
[sagemath_doc_html-none] [spkg-install]   File "/home/release/Sage/src/sage/repl/all.py", line 12, in <module>
[sagemath_doc_html-none] [spkg-install]     from sage.repl.rich_output.display_manager import get_display_manager
[sagemath_doc_html-none] [spkg-install]   File "/home/release/Sage/src/sage/repl/rich_output/__init__.py", line 3, in <module>
[sagemath_doc_html-none] [spkg-install]     from .display_manager import get_display_manager
[sagemath_doc_html-none] [spkg-install]   File "/home/release/Sage/src/sage/repl/rich_output/display_manager.py", line 40, in <module>
[sagemath_doc_html-none] [spkg-install]     from typing_extensions import Self
[sagemath_doc_html-none] [spkg-install] ModuleNotFoundError: No module named 'typing_extensions'
[sagemath_doc_html-none] [spkg-install] Error: 'sage --docbuild --all-documents' failed
[sagemath_doc_html-none] [spkg-install] make[5]: *** [Makefile:41: doc-inventory-reference] Error 1
[sagemath_doc_html-none] ************************************************************************
[sagemath_doc_html-none] Error installing package sagemath_doc_html-none
[sagemath_doc_html-none] ************************************************************************
[sagemath_doc_html-none] Please email sage-devel (http://groups.google.com/group/sage-devel)
[sagemath_doc_html-none] explaining the problem and including the log files
[sagemath_doc_html-none]   /home/release/Sage/logs/pkgs/sagemath_doc_html-none.log
[sagemath_doc_html-none] and
[sagemath_doc_html-none]   /home/release/Sage/config.log
[sagemath_doc_html-none] Describe your computer, operating system, etc.
[sagemath_doc_html-none] If you want to try to fix the problem yourself, *don't* just cd to
[sagemath_doc_html-none] /home/release/Sage/local/var/tmp/sage/build/sagemath_doc_html-none and type 'make' or whatever is appropriate.
[sagemath_doc_html-none] Instead, the following commands setup all environment variables
[sagemath_doc_html-none] correctly and load a subshell for you to debug the error:
[sagemath_doc_html-none]   (cd '/home/release/Sage/local/var/tmp/sage/build/sagemath_doc_html-none' && '/home/release/Sage/sage' --buildsh)
[sagemath_doc_html-none] When you are done debugging, you can type "exit" to leave the subshell.
[sagemath_doc_html-none] ************************************************************************

fwiw Self is also in the typing module since Python 3.11, but backward compatibility needs typing_extensions installed

@tobiasdiez
Copy link
Contributor Author

@vbraun Is this with python 3.11? typing_extensions is a standard dependency of sagelib, so I don't understand why it's not automatically installed. I've added it now as explicit dependency, and first try to import from typing. Does this work for you?

@vbraun
Copy link
Member

vbraun commented Jan 1, 2025

For the record Sage Python is 3.12.5, OS Python is 3.13.0. I haven't tried to figure out why typing_extensions was not installed

vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 1, 2025
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

With these changes it should now be possible to run doctests via pytest:
e.g. `pytest --doctest src/sage/manifolds`.

There are still a lot of errors since pytests handles a few things
differently (most notable it doesn't isolate tests from each other).
These issues will be fixed in follow-ups.

I've also moved the pytest config from `src` to the root for better
vscode integration. Added also a bit of typing information in the
doctest framework.

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [ ] The title is concise and informative.
- [ ] 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 and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39206
Reported by: Tobias Diez
Reviewer(s): Dima Pasechnik
@vbraun vbraun merged commit 8cf2231 into sagemath:develop Jan 4, 2025
16 of 22 checks passed
@user202729
Copy link
Contributor

user202729 commented Jan 5, 2025

This still causes failure in test-mod because of typing_extensions not installed. https://github.com/sagemath/sage/actions/runs/12612611945/job/35153776761?pr=39279

which… makes sense (?) the dependency specification of modularized distribution is separate e.g. build/pkgs/sagemath_repl/dependencies file? (not entirely sure how it works)

@tobiasdiez tobiasdiez deleted the pytest_doctest branch January 5, 2025 03:46
@tobiasdiez
Copy link
Contributor Author

This still causes failure in test-mod because of typing_extensions not installed. https://github.com/sagemath/sage/actions/runs/12612611945/job/35153776761?pr=39279

I think its safe to ignore this failure (nobody is actually working on the modularized distributions and they have a lot of issues)

which… makes sense (?) the dependency specification of modularized distribution is separate e.g. build/pkgs/sagemath_repl/dependencies file? (not entirely sure how it works)

Would be surprised to find someone that actually understands how this works ;-)

@user202729
Copy link
Contributor

Feel like we can save some CO₂ emission (and developer time by looking at notification of CI failure) by (temporarily?) comment out test-mod in .github/workflows/build.yml then.

@dimpase
Copy link
Member

dimpase commented Jan 5, 2025

Yes, that's a good idea.

@tobiasdiez
Copy link
Contributor Author

Done at #39284

vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 7, 2025
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

As suggested at
sagemath#39206 (comment).

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [ ] The title is concise and informative.
- [ ] 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 and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39284
Reported by: Tobias Diez
Reviewer(s): Dima Pasechnik
vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 9, 2025
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

As suggested at
sagemath#39206 (comment).

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [ ] The title is concise and informative.
- [ ] 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 and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39284
Reported by: Tobias Diez
Reviewer(s): Dima Pasechnik
vbraun pushed a commit to vbraun/sage that referenced this pull request Jan 10, 2025
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->

As suggested at
sagemath#39206 (comment).

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [ ] The title is concise and informative.
- [ ] 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 and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#39284
Reported by: Tobias Diez
Reviewer(s): Dima Pasechnik
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.

4 participants