8000 Q: Using `assert` vs `numpy.testing.assert_` in testing · Issue #8583 · scipy/scipy · GitHub
[go: up one dir, main page]

Skip to content
Q: Using assert vs numpy.testing.assert_ in testing #8583
@larsoner

Description

@larsoner

A few times the idea of using direct assert statements in tests rather than assert_ from numpy.testing has come up. IIUC pytest guarantees that assert statements are executed.

Some advantages of assert :

  1. Simplicity. No need for imports.
  2. Improved tracebacks. pytest has put work into making assert error messages readable for diagnosing problems.
  3. Long-term consistency (?). I have seen a proliferation of assert statements in other packages, so that seems to be the zeitgeist.
  4. Lowering contribution/review burden. Given the increasing use of assert , the probability of contributors using it assuming it's acceptable increases, and allowing its use is one fewer thing we have to nitpick.

Some advantages of numpy.testing.assert_

  1. Internal consistency (near-/medium-term). We have historically used assert_ and have 1561 of instances according to git grep "assert_(" | wc -l.
  2. Guaranteed support. numpy.testing can be guaranteed to work as long as numpy does, whereas assert relies on pytest maintenance and/or pytest-compatible assert support by any future testing framework.

There are probably others, feel free to comment and/or edit this top comment to keep track.

My +1 is for allowing assert if people want to use it. I have begun moving a few of my other repos to follow this pattern and so far have found it beneficial.

Metadata

Metadata

Assignees

No one assigned

    Labels

    queryA question or suggestion that requires further information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0