-
Notifications
You must be signed in to change notification settings - Fork 235
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
Ensure no unexpected warnings are emitted during test suite runs #1363
Comments
Example from idaes-pse/idaes/core/base/tests/test_var_like_expression.py Lines 37 to 42 in bc2f6c0
import re
...
with pytest.raises(
TypeError,
match=re.escape(
"e is an Expression and does not have a value "
"attribute. Use the 'value()' method instead."
),
):
assert m.e.value == 42 |
It appears the way to address these warnings is to deprecate and/or remove older (unmaintained) parts of the code base. |
|
Peripherally related to this, but when running tests on a new Windows machine (I used Linux previously), I discovered that the |
-W ignore
flag in Restore ability to run pytest on individual files or directories #1362 caused warnings emitted during pytest run to be shown again (see below for a list)pytest.warns()
(which as I understand is equivalent topytest.raises()
used for exceptions)General strategies
SyntaxWarning
invalid escape sequencepytest.raises(match=expected_str)
:expected_str
is supposed to be a plain string (i.e. containing no regexes), usere.escape()
expected_str
contains both regex constructs and regex symbols that should not be interpreted as regexes, defineexpected_str
as raw literals usingr"..."
, e.g.r"[a-z]+.my_dict\[key\]"
PytestCollectionWarning
: cannot collect test class 'TestXYZ' because it has a init constructorTestXYZ
class is supposed to be a pytest test class (i.e. its methods should be collected as pytest test functions), remove the__init__()
definitionTestXYZ
class is not supposed to be a pytest class, change its name so that it doesn't collide with theTest
prefix used by pytest, e.g.SampleXYZ
XYZForTesting
PytestReturnNotNoneWarning
: ExpectedNone
, but<test-function>
returned<object>
, which will be an error in a future version of pytest. Did you mean to useassert
instead ofreturn
?idaes/apps/matopt
have thisThe text was updated successfully, but these errors were encountered: