
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
65 lines
1.4 KiB
Plaintext
65 lines
1.4 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Using the ``++assert++`` statement on a tuple literal will always fail if the tuple is empty, and always succeed otherwise.
|
|
|
|
|
|
The ``++assert++`` statement does not have parentheses around its parameters. Calling ``++assert(x, y)++`` will test if the tuple ``++(x, y)++`` is True, which is always the case.
|
|
|
|
|
|
There are two possible fixes:
|
|
|
|
* If your intention is to test the first value of the tuple and use the second value as a message, simply remove the parentheses.
|
|
* If your intention is to check that every element of the tuple is ``++True++``, test each value separately.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
def test_values(a, b):
|
|
assert (a, b) # Noncompliant
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
def test_values(a, b):
|
|
# If you mean to test "a" and use "b" as an error message
|
|
assert a, b
|
|
|
|
# If you mean to test the values of "a" and "b"
|
|
assert a and b
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement[Python documentation - The ``++assert++`` statement]
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Fix this assertion on a tuple literal; did you mean "assert A, B".
|
|
|
|
|
|
=== Highlighting
|
|
|
|
The tuple parameter
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== deprecates: S1721
|
|
|
|
endif::env-github,rspecator-view[]
|