Skip to content

modernize testing code #3743

Description

@orbeckst

Is your feature request related to a problem?

The testing code uses pytest and relies on numpy.testing. It contains some deprecated testing constructs such as assert_almost_equal(), assert_array_almost_equal() and some sub-optimal tests (such as testing single floats with an array assertion).

Describe the solution you'd like

Update the testing code, following current best practices, such as

  1. use numpy.testing.assert_allclose() instead of assert_almost_equal() or assert_array_almost_equal() for more consistent floating point comparisons
  2. replace array comparisons for floating point scalars (a single floating point number) with pytest.approx() (see Nuclinfo Major Pair and Minor Pair overhaul #3735 (comment))
  3. ...

Please add additional best practices here or in the comments.

Describe alternatives you've considered

We don't have to do anything right now because everything is working.

How to work on this issue

You can open issues for individual points above, you don't have to work on all of them. If you create a new issue, mention this issue number in the issue text so that it gets linked.

Find occurrences of the constructs that you want to change in the code, e.g.,

cd testsuite/
git grep 'assert_almost_equal'

Figure out how to change the code to get an equivalent result by learning about the different arguments that the old and the new function take and how they affect the assertion. Then pick one example and implement your solution. See if it works. Improve your example until it works. Only then start converting more of the test files. Get feedback from other developers.

Activity

  1. utkarsh147-del commented on Jul 9, 2022

    @utkarsh147-del

    i want to work on this issue

  2. orbeckst commented on Jul 9, 2022

    @orbeckst
    MemberAuthor

    We always welcome contributions. Just submit a PR that references this issue. We will then discuss there. When you start the work, please also introduce you on the developer mailing list.

    Btw, we don’t “reserve” work, we just look at the first PR that addresses the issue. Details of our policy are in our GSOC FAQ on our wiki.

  3. rzhao271 commented on Jul 23, 2022

    @rzhao271
    Contributor

    I tried converting more tests to use assert_allclose instead of assert_almost_equals, but an issue I've run into is that for scalars, pytest.approx doesn't work well when the original test had a custom error message.
    Here's how the signature looks for assert_almost_equals:
    assert_almost_equals(a, b, rtol=0, atol=something, err_msg=something)
    But for pytest.approx, one uses it as follows:
    assert a == approx(b, abs=something)
    I'm wondering if I can just use assert_allclose instead? Otherwise I'd have to write something like

    if a != approx(b):
        # print the custom error message here and fail the test

    for those tests.

  4. orbeckst commented on Jul 23, 2022

    @orbeckst
    MemberAuthor

    Does

    assert a == approx(b), “error message”
    

    work?

  5. Ranit-Bandyopadhyay commented on Jan 16, 2023

    @Ranit-Bandyopadhyay

    hello, i want to work on this project.

  6. orbeckst commented on Jan 16, 2023

    @orbeckst
    MemberAuthor

    Hello @Ranit-Bandyopadhyay , if no-body else is working on an issue as evidenced by a linked PR, just go ahead an submit a PR. See also our GSOC FAQ https://github.com/MDAnalysis/mdanalysis/wiki/GSoC-FAQ#can-i-claim-an-issue-to-work-on .

  7. chandra20500 commented on Feb 10, 2023

    @chandra20500

    Hi, I would like to work on this Issue. it would be great could you please assign this issue to me

  8. orbeckst commented on Feb 10, 2023

    @orbeckst
    MemberAuthor

    @chandra20500 , see what I said above and read the link to the FAQ: we do not reserve or assign issues. We just evaluate work presented.

  9. utkarsh147-del commented on Feb 12, 2023

    @utkarsh147-del

    can u tell me the link of testing code

  10. hmacdope commented on Feb 12, 2023

    @hmacdope
    Member

    @utkarsh147-del you can find the link by reading the User Guide

  11. 22 remaining items

  12. added 2 commits that reference this issue on Dec 7, 2025
    b5e65a2
    a4b357f
  13. deekshithdeekshith020-ux commented on Dec 20, 2025

    @deekshithdeekshith020-ux

    hey team , is there any remaining work that need to be done here , i want to contribute to md analysis and its my first contribution please guide me assign me to this do this work. so in simple words the problem here is : From my understanding, the goal is to replace the current raw assert statements in the test suite with NumPy’s dedicated testing functions (such as np.testing.assert_equal, np.testing.assert_allclose, etc.), so that numerical and array comparisons become more reliable and consistent with best practices.
    I plan to start by locating such asserts in the tests, update them gradually, and verify using pytest that everything still passes.
    Please let me know if this plan sounds good or if there are any preferred files to begin with 😊@orbeckst sir.

  14. marinegor commented on Dec 23, 2025

    @marinegor
    Contributor

    @deekshithdeekshith020-ux

    please guide me assign me to this do this work.

    I'd suggest familiarizing yourself with the contribution guide here: https://userguide.mdanalysis.org/stable/contributing.html

    For this particular issue, I'd suggest checking some associated PRs (e.g. #5156) and do a similar body of work.

  15. Kd1880 commented on Mar 5, 2026

    @Kd1880

    Hi! I'm new to MDAnalysis and interested in contributing.
    I'd like to work on this issue if it's still available.

  16. added 2 commits that reference this issue on Mar 11, 2026
    60e2958
    60c99a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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