-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #33546: Use pytest to run doctests
As suggested in https://trac.sagemath.org/ticket/33232#comment:1, `./sage --pytest` now uses pytest to discover and run doctests. To test, run `./sage --pytest src/sage/manifolds/`. This results in {{{ 48 failed, 1416 passed, 7 warnings }}} With many of the failed tests being due to some issues with assumptions and/or symbolic variables and/or deprecation warnings. To see examples of these failures, run pytest on {{{ src/sage/manifolds/differentiable/examples/sphere.py src/sage/manifolds/utilities.py src/sage/manifolds/chart.py }}} We also add tests that verify that `sage --pytest` (and `sage -t`) correctly complain about failing doctests. Follow-ups: - #33826 Fix these issues - #33825 Use `pytest-parallel` or `pytest-xdist` to run pytest in parallel - #33827 Also run doctests defined in cython files using https://github.com/lgpage/pytest-cython URL: https://trac.sagemath.org/33546 Reported by: mkoeppe Ticket author(s): Tobias Diez Reviewer(s): Matthias Koeppe
- Loading branch information
Showing
7 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def something(): | ||
""" a doctest in a docstring | ||
EXAMPLES:: | ||
sage: something() | ||
42 | ||
sage: something() + 1 | ||
43 | ||
TESTS:: | ||
sage: something() | ||
44 | ||
""" | ||
return 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import subprocess | ||
|
||
|
||
class TestOldDoctestSageScript: | ||
"""Run `sage --t`.""" | ||
|
||
def test_invoke_on_inputtest_file(self): | ||
result = subprocess.run( | ||
["sage", "-t", "./src/conftest_inputtest.py"], | ||
capture_output=True, | ||
text=True, | ||
) | ||
assert result.returncode == 1 # There are failures in the input test | ||
assert ( | ||
"Failed example:\n" | ||
" something()\n" | ||
"Expected:\n" | ||
" 44\n" | ||
"Got:\n" | ||
" 42\n" | ||
"" in result.stdout | ||
) | ||
|
||
|
||
class TestPytestSageScript: | ||
"""Run `sage --pytest`.""" | ||
|
||
def test_invoke_on_inputtest_file(self): | ||
result = subprocess.run( | ||
["sage", "--pytest", "./src/conftest_inputtest.py"], | ||
capture_output=True, | ||
text=True, | ||
) | ||
assert result.returncode == 1 # There are failures in the input test | ||
assert ( | ||
"004 EXAMPLES::\n" | ||
"005 \n" | ||
"006 sage: something()\n" | ||
"007 42\n" | ||
"008 sage: something() + 1\n" | ||
"009 43\n" | ||
"010 \n" | ||
"011 TESTS::\n" | ||
"012 \n" | ||
"013 sage: something()\n" | ||
"Expected:\n" | ||
" 44\n" | ||
"Got:\n" | ||
" 42\n" | ||
"" in result.stdout | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters