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

Running doctests using doctest-plus #4117

Merged
merged 22 commits into from
Jun 7, 2024

Conversation

prady0t
Copy link
Contributor

@prady0t prady0t commented May 29, 2024

Description

Running doctests on /pybamm using pytest's doctest-plus plugin. We decided to move ahead with doctestplus as xdoctest was throwing random internal errors. See discussion here.

Fixes #4031
Also addresses #3617

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@prady0t
Copy link
Contributor Author

prady0t commented May 29, 2024

Still working on latexify error.

@agriyakhetarpal
Copy link
Member

I think it makes sense to skip the failing doctest. The functionality is being tested in the unit tests, and testing through a doctest whether a PNG or the LaTeX form of an equation can be printed out or not is quite inconvenient. Please see https://github.com/scientific-python/pytest-doctestplus#skipping-tests for instructions.

@prady0t
Copy link
Contributor Author

prady0t commented May 29, 2024

I think it makes sense to skip the failing doctest. The functionality is being tested in the unit tests, and testing through a doctest whether a PNG or the LaTeX form of an equation can be printed out or not is quite inconvenient. Please see https://github.com/scientific-python/pytest-doctestplus#skipping-tests for instructions.

Makes sense. Skipping these tests.

run-tests.py Outdated Show resolved Hide resolved
run-tests.py Outdated Show resolved Hide resolved
run-tests.py Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
pybamm/models/full_battery_models/lithium_metal/dfn.py Outdated Show resolved Hide resolved
@agriyakhetarpal
Copy link
Member

The doctests failed because of the now redundant .. doctest:: directive that Sphinx won't recognise without sphinx.ext.doctest. The Windows build is unrelated, I triggered a re-run for it.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

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

Looks good to me! I added a few suggestions plus a fix for the failing doctest. Thanks, @prady0t!

docs/source/user_guide/installation/index.rst Outdated Show resolved Hide resolved
docs/source/user_guide/installation/index.rst Outdated Show resolved Hide resolved
pybamm/parameters/parameter_sets.py Outdated Show resolved Hide resolved
prady0t and others added 4 commits June 5, 2024 22:35
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
@agriyakhetarpal
Copy link
Member

Looks like there's another one of the .. doctest:: directives below the one that we removed – could you fix that, @prady0t? This should be good to merge after that.

prady0t and others added 2 commits June 6, 2024 15:08
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@prady0t
Copy link
Contributor Author

prady0t commented Jun 6, 2024

Done!

@prady0t
Copy link
Contributor Author

prady0t commented Jun 7, 2024

Test failure due to non-matching hashes happens quite frequently. Why does it happen? Is there a way to fix it?

Downloading types_python_dateutil-2.9.0.20240316-py3-none-any.whl (9.7 kB)
ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
    unknown package:
        Expected sha256 d37f1d8cab6fca11d8ba44d6404fdbb9b796d4e6f447d12317e4ce0660310072
             Got        f6974e35bc2c42ad0002e80e04815ae8f65a012154c0de8b4daf00c9417b8bb4

Copy link

codecov bot commented Jun 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.56%. Comparing base (b4f8380) to head (c20d315).
Report is 218 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4117      +/-   ##
===========================================
+ Coverage    99.55%   99.56%   +0.01%     
===========================================
  Files          288      288              
  Lines        21790    21790              
===========================================
+ Hits         21693    21696       +3     
+ Misses          97       94       -3     

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

@agriyakhetarpal
Copy link
Member

Test failure due to non-matching hashes happens quite frequently. Why does it happen? Is there a way to fix it?

This is a bug with pip's hash-checking functionality. I assume there are three intermittent factors that can lead to the error:

  1. pip either computes the SHA-256 checksum of the cached types_python_dateutil package incorrectly
  2. pip either receives an incorrect SHA-256 checksum and that for the cached types_python_dateutil is correct
  3. The GitHub Actions cache mechanisms are corrupted or that they corrupt this file (a bit unlikely).

Either way, a re-run typically fixes the issue, but it's strange that it happens with types_python_dateutil everytime I see it.

@agriyakhetarpal agriyakhetarpal merged commit 11dcf6a into pybamm-team:develop Jun 7, 2024
26 checks passed
@agriyakhetarpal
Copy link
Member

Thanks for your work, @prady0t!

@prady0t
Copy link
Contributor Author

prady0t commented Jun 7, 2024

Test failure due to non-matching hashes happens quite frequently. Why does it happen? Is there a way to fix it?

This is a bug with pip's hash-checking functionality. I assume there are three intermittent factors that can lead to the error:

  1. pip either computes the SHA-256 checksum of the cached types_python_dateutil package incorrectly
  2. pip either receives an incorrect SHA-256 checksum and that for the cached types_python_dateutil is correct
  3. The GitHub Actions cache mechanisms are corrupted or that they corrupt this file (a bit unlikely).

Either way, a re-run typically fixes the issue, but it's strange that it happens with types_python_dateutil everytime I see it.

I see 🤔 So we can't do anything about it for the moment.

js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
* Adding doctest using doctest-plus

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* Skipping failing tests

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* Update run-tests.py

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* style: pre-commit fixes

* Removing unrelated subprocess

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

* style: pre-commit fixes

* Update docs/source/user_guide/installation/index.rst

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* Update docs/source/user_guide/installation/index.rst

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* Update pybamm/parameters/parameter_sets.py

Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>

* Fixing doctest directive

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>

---------

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Co-authored-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Co-authored-by: Eric G. Kratz <kratman@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Arjun Verma <arjunverma.oc@gmail.com>
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.

Add support for pytest-doctestplus
4 participants