Some of the top search-engine hits for pytest.approx use the function without actually comparing it to anything. This PR will cause these tests to fail by implementing approx.__bool__() to raise an AssertionError that briefly explains how to correctly use approx.
16 lines
398 B
ReStructuredText
16 lines
398 B
ReStructuredText
Using :func:`pytest.approx` in a boolean context now raises an error hinting at the proper usage.
|
|
|
|
It is apparently common for users to mistakenly use ``pytest.approx`` like this:
|
|
|
|
.. code-block:: python
|
|
|
|
assert pytest.approx(actual, expected)
|
|
|
|
While the correct usage is:
|
|
|
|
.. code-block:: python
|
|
|
|
assert actual == pytest.approx(expected)
|
|
|
|
The new error message helps catch those mistakes.
|