Do not trigger warning about tuples being always True if the tuple has size != 2
This commit is contained in:
parent
615c671434
commit
9ae0a3cd85
|
@ -750,7 +750,7 @@ class AssertionRewriter(ast.NodeVisitor):
|
||||||
the expression is false.
|
the expression is false.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(assert_.test, ast.Tuple):
|
if isinstance(assert_.test, ast.Tuple) and len(assert_.test.elts) == 2:
|
||||||
from _pytest.warning_types import PytestWarning
|
from _pytest.warning_types import PytestWarning
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
|
|
|
@ -1077,16 +1077,25 @@ def test_diff_newline_at_end(monkeypatch, testdir):
|
||||||
|
|
||||||
@pytest.mark.filterwarnings("default")
|
@pytest.mark.filterwarnings("default")
|
||||||
def test_assert_tuple_warning(testdir):
|
def test_assert_tuple_warning(testdir):
|
||||||
|
msg = "assertion is always true"
|
||||||
testdir.makepyfile(
|
testdir.makepyfile(
|
||||||
"""
|
"""
|
||||||
def test_tuple():
|
def test_tuple():
|
||||||
assert(False, 'you shall not pass')
|
assert(False, 'you shall not pass')
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
result = testdir.runpytest("-rw")
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines(
|
result.stdout.fnmatch_lines(["*test_assert_tuple_warning.py:2:*{}*".format(msg)])
|
||||||
["*test_assert_tuple_warning.py:2:*assertion is always true*"]
|
|
||||||
|
# tuples with size != 2 should not trigger the warning
|
||||||
|
testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_tuple():
|
||||||
|
assert ()
|
||||||
|
"""
|
||||||
)
|
)
|
||||||
|
result = testdir.runpytest()
|
||||||
|
assert msg not in result.stdout.str()
|
||||||
|
|
||||||
|
|
||||||
def test_assert_indirect_tuple_no_warning(testdir):
|
def test_assert_indirect_tuple_no_warning(testdir):
|
||||||
|
|
Loading…
Reference in New Issue