Skip to content

pytest in sage is broken, please make it really optional #33531

@tornaria

Description

@tornaria
$ time sage -t src/sage/all.py ; echo $?
Running doctests with ID 2022-03-19-12-07-01-0e558614.
Using --optional=build,pip,sage,sage_spkg,void
Features to be detected: 4ti2,benzene,bliss,buckygen,conway_polynomials,csdp,database_cremona_ellcurve,database_cremona_mini_ellcurve,database_jones_numfield,database_knotinfo,dvipng,graphviz,imagemagick,jupymake,kenzo,latte_int,lrslib,mcqd,meataxe,pandoc,pdf2svg,plantri,pynormaliz,rubiks,sage.combinat,sage.geometry.polyhedron,sage.graphs,sage.plot,sage.rings.number_field,sage.rings.real_double,sage.symbolic,sage_numerical_backends_coin,sagemath_doc_html,sphinx,tdlib
Doctesting 1 file.
sage -t --warn-long 60.2 --random-seed=67815784290108767013007019285883868229 src/sage/all.py
    [13 tests, 0.75 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 0.8 seconds
    cpu time: 0.7 seconds
    cumulative wall time: 0.7 seconds
Features detected for doctesting: 
============================================================================ test session starts =============================================================================
platform linux -- Python 3.10.3, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: /opt/sage/sage-git/develop/src, configfile: tox.ini
plugins: anyio-3.5.0, xonsh-0.11.0
collected 0 items / 1 error                                                                                                                                                  

=================================================================================== ERRORS ===================================================================================
________________________________________________________________________ ERROR collecting sage/all.py ________________________________________________________________________
src/sage/all.py:315: in <module>
    sage.misc.lazy_import.finish_startup()
sage/misc/lazy_import.pyx:87: in sage.misc.lazy_import.finish_startup (build/cythonized/sage/misc/lazy_import.c:1995)
    ???
sage/misc/lazy_import.pyx:103: in sage.misc.lazy_import.finish_startup (build/cythonized/sage/misc/lazy_import.c:1929)
    ???
E   AssertionError: finish_startup() must be called exactly once
========================================================================== short test summary info ===========================================================================
ERROR src/sage/all.py - AssertionError: finish_startup() must be called exactly once
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================== 1 error in 0.34s ==============================================================================

real	0m6.917s
user	0m6.496s
sys	0m0.486s
2

Expected behaviour (this is what happens when pytest is patched out in sage-runtests):

$ time sage -t src/sage/all.py ; echo $?
Running doctests with ID 2022-03-19-12-07-20-a46d44e6.
Using --optional=build,pip,sage,sage_spkg,void
Features to be detected: 4ti2,benzene,bliss,buckygen,conway_polynomials,csdp,database_cremona_ellcurve,database_cremona_mini_ellcurve,database_jones_numfield,database_knotinfo,dvipng,graphviz,imagemagick,jupymake,kenzo,latte_int,lrslib,mcqd,meataxe,pandoc,pdf2svg,plantri,pynormaliz,rubiks,sage.combinat,sage.geometry.polyhedron,sage.graphs,sage.plot,sage.rings.number_field,sage.rings.real_double,sage.symbolic,sage_numerical_backends_coin,sagemath_doc_html,sphinx,tdlib
Doctesting 1 file.
sage -t --warn-long 60.2 --random-seed=339422732397923267068138499972932430419 src/sage/all.py
    [13 tests, 0.75 s]
----------------------------------------------------------------------
All tests passed!
----------------------------------------------------------------------
Total time for all tests: 0.8 seconds
    cpu time: 0.8 seconds
    cumulative wall time: 0.8 seconds
Features detected for doctesting: 

real	0m4.115s
user	0m3.783s
sys	0m0.323s
0

My proposal:

In fact pytest should only run when there's some file *_test.py in the list of files, and only in those files. I think DC already traversed the filesystem in search of files, so instead of having pytest traverse the filesystem again, just filter the list of files that DC obtained for *_test.py and run pytest just on those and only if there's some.

Even if/after pytest integration is fixed, there are advantages to place it behind a feature flag so there's an easy way to run doctests skipping pytest (just add --optional=sage or whatever else one wants to test, leaving out pytest)

Depends on #31924

CC: @tobiasdiez @mkoeppe

Component: doctest framework

Reviewer: Gonzalo Tornaría

Issue created by migration from https://trac.sagemath.org/ticket/33531

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions