-
Notifications
You must be signed in to change notification settings - Fork 470
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
Switching to pytest for unit testing framework; Use doctest more extensively #947
Comments
I am +1 on this. |
I would also like to migrate to Numpy docs and use doctest more extensively to make sure that the documentation is always up to date. |
In #954, I'm working on switching Travis CI to use pytest instead of unittest. However, I think this issue should remain open for the reminder on migrating to NumPy docs and using doctest more extensively? |
954: Switch Travis CI test configuration to pytest and add matplotlib tests r=hgrecco a=jthielen As discussed in #947, this PR switches Travis CI to use pytest for Pint's test suite instead of unittest. As a motivating example, basic tests for `pint.matplotlib` are added (which closes #897). - [x] Closes #897, towards #947 (but does not fully resolve it) - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - [x] The change is fully covered by automated unit tests - ~~Documented in docs/ as appropriate~~ - [x] Added an entry to the CHANGES file Co-authored-by: Jon Thielen <github@jont.cc>
I agree |
I am trying pyment to migrate the docs |
958: Migrates docstring to Numpy docs r=hgrecco a=hgrecco As defined here https://numpydoc.readthedocs.io/en/latest/format.html - [ ] ~~Closes # (insert issue number)~~ - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - [ ] ~~The change is fully covered by automated unit tests~~ - [ ] ~~Documented in docs/ as appropriate~~ - [x] Added an entry to the CHANGES file See #947 Co-authored-by: Hernan <hernan.grecco@gmail.com>
While this is partly complete, I am phasing this to 0.11 because I think we should make a more in depth change before closing this issue. |
@hgrecco What's the recommended way of running the doctests? (Or even the whole test suite in general?) If I run naked
I get 18 tests and 11 failures, and the output looks like legitimate (albeit mostly minor) failures, which makes me wonder if doctests are being skipped in CI. None of the following invocations replicates that behavior, so I'm at a bit of a loss:
(Happy to submit a PR updating developer docs with the recommended local environment setup and test suite invocations) |
I would use python -m pytest --doctest-modules --ignore=pint/testsuite which I believe will run the doctests it can find (remove the |
Hmm, that works to run the tests in the module docstrings, but not for any of the
Which, as of f8ec2ca is giving me:
Which are more believable numbers given there's 209 blocks marked with If that is indeed the correct way of running the Sphinx doctests, it looks like we need to:
|
It would also be good to see double check that all the docstrings are writen using the Numpy style, and the API docs are nicely generated. |
It looks like the package
Perhaps if we suppressed D102 and D105 the rest would be manageable? |
1116: Harmonize most doctests with Pint's current behavior r=hgrecco a=clarkgwillison - [ ] Closes # (no single issue) - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - [x] The change is fully covered by automated unit tests - [x] Documented in docs/ as appropriate - [x] Added an entry to the CHANGES file This PR partially addresses #947, #972, and #990 After merging, the number of failing doctests in the Sphinx documentation should go from 92 (as mentioned in #947) down to 3: ``` Doctest summary =============== 335 tests 3 failures in tests 0 failures in setup code 0 failures in cleanup code build finished with problems. make: *** [doctest] Error 1 ``` Which will put us well in reach of enabling doctests in Travis to prevent documentation regressions in the future. Most tests were fixed in this PR by deferring to the current behavior of Pint, however `Quantity.__repr__()` was modified to round floating point magnitudes to 9 digits to avoid several test failures that were being caused by floating point ambiguities. Issue #1115 was opened to track the 3 tests that I could not easily resolve. Once that issue is resolved, we can enable doctests in Travis without breaking CI. Co-authored-by: Clark Willison <clarkgwillison@gmail.com>
@clarkgwillison I was not aware of this tool. Thanks for the pointing this out. I was surprised by the result because I knew that most of the code is documented. Then I realized that the test folder was counted. Ignoring the testsuite folder provides a more accurate result:
Having said this, I would agree to ignore D105. |
or better: |
Nice, that does make the numbers look a lot better. Given the amount of work to get to zero here, it might make sense to go for a longer term goal (like getting to coverage 100%) Is there a way to implement "check the # errors didn't increase" rather than "check that # errors is zero" in Travis? |
I don't think that is possible. My suggestion is that you add this test and label it as expected failure. Having that reporting this would be enough for now. |
Maybe it can be done with a bit of customization, by telling flake8 to check only the diffs. We do something like that (for flake8, not flake8-docstings) here |
I have just pushed a new branch _pytest_migration in which If there are now complains, I will rebase it on top of master and merge it on Jan 17. Just to summarize what can be improved:
|
1235: Pytest migration r=hgrecco a=hgrecco - [x] Closes #947 (insert issue number) - [x] Executed ``pre-commit run --all-files`` with no errors - [x] The change is fully covered by automated unit tests - [x] Documented in docs/ as appropriate - [x] Added an entry to the CHANGES file Co-authored-by: Hernan <hernan.grecco@gmail.com> Co-authored-by: Hernan Grecco <hernan.grecco@gmail.com>
Would there be support for moving to pytest as the unit testing framework for Pint over unittest? I think this would be a worthwhile move for a couple reasons:
unittest.TestCase
support would make it an easy transition@hgrecco What are your thoughts on this?
The text was updated successfully, but these errors were encountered: