Skip to content

numpy/legacy-testing-helper

Rule legacy-testing-helper
Pack NumPy
Severity info
Fix unsafe, with xpd check --fix --unsafe-fixes
Library versions every version

numpy.testing.assert_ is the legacy form of the assert statement. Write a plain assert, which pytest shows with the compared values, and use pytest.raises for exceptions.

assert_(res.success, res.message)
assert res.success, res.message

The rule reports numpy.testing.assert_, which NumPy's testing guidelines call the legacy form of the assert statement. It also reports numpy.testing.assert_raises and assert_raises_regex, where the guidelines prefer pytest.raises. The rule reports a bare assert_raises only in a file that imports it from numpy.testing, because SciPy imports pytest.raises under that name.

xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.

The unsafe fix writes assert x and assert x, msg, with each part in parentheses when the call is on more than one line. The statement is skipped under python -O, and its message is built only on failure. assert_raises has no fix.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

assert_ is the legacy form of the assert statement, which pytest rewrites to show the compared values. Write assert $X.

Browse the other rules of the NumPy pack.