Repository: wemake-services/wemake-python-styleguide

Issue:
`WPS520` should be ignore in `assert` context
pytest does not like this rule.

```

  47:37    WPS520 Found compare with falsy constant
  assert task_json['args'] == []
                              ^
```

Discussion:
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/wemake-services/wemake-python-styleguide/pull/3117?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wemake-services) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`e9a03c5`)](https://app.codecov.io/gh/wemake-services/wemake-python-styleguide/commit/e9a03c5c8ebe4f7176ee12f48ad4cc8161f492b6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wemake-services) to head [(`ce461e3`)](https://app.codecov.io/gh/wemake-services/wemake-python-styleguide/commit/ce461e32efa1682f1fed112df3a6558062456218?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wemake-services).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##            master     #3117   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          121       121           
  Lines         6620      6593   -27     
  Branches      1005      1004    -1     
=========================================
- Hits          6620      6593   -27     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/wemake-services/wemake-python-styleguide/pull/3117?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wemake-services).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=wemake-services).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4cb9c48f..7e6e2fe5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ Semantic versioning in our case means:
 ### Features
 
 - Adds official `python3.13` support
+- Allows any compares in `assert` statements for `WPS520`, #3112
 
 ### Bugfixes
 
diff --git a/wemake_python_styleguide/violations/refactoring.py b/wemake_python_styleguide/violations/refactoring.py
index 93e169d9..ef106510 100644
--- a/wemake_python_styleguide/violations/refactoring.py
+++ b/wemake_python_styleguide/violations/refactoring.py
@@ -847,6 +847,7 @@ class FalsyConstantCompareViolation(ASTViolation):
 
     We allow to compare with falsy numbers, strings, booleans, ``None``.
     We disallow complex constants like tuple, dicts, and lists.
+    We also allow to compare any values inside ``assert`` statements.
 
     Reasoning:
         When comparing ``something`` with explicit falsy constants
@@ -873,6 +874,7 @@ class FalsyConstantCompareViolation(ASTViolation):
             ...
 
     .. versionadded:: 0.12.0
+    .. versionchanged:: 1.0.0
 
     """
 
diff --git a/wemake_python_styleguide/visitors/ast/compares.py b/wemake_python_styleguide/visitors/ast/compares.py
index a88cec1e..e7d936d4 100644
--- a/wemake_python_styleguide/visitors/ast/compares.py
+++ b/wemake_python_styleguide/visitors/ast/compares.py
@@ -156,6 +156,8 @@ class WrongConstantCompareVisitor(BaseNodeVisitor):
         real = get_assigned_expr(comparator)
         if not isinstance(real, (ast.List, ast.Dict, ast.Tuple)):
             return
+        if walk.get_closest_parent(op, ast.Assert):
+            return  # We allow any compares in `assert`
 
         length = len(real.keys) if isinstance(
             real, ast.Dict,


Test patch:
diff --git a/tests/test_visitors/test_ast/test_compares/test_constant_compares/test_falsy_constant.py b/tests/test_visitors/test_ast/test_compares/test_constant_compares/test_falsy_constant.py
index b72e59d3..1912ef9c 100644
--- a/tests/test_visitors/test_ast/test_compares/test_constant_compares/test_falsy_constant.py
+++ b/tests/test_visitors/test_ast/test_compares/test_constant_compares/test_falsy_constant.py
@@ -21,6 +21,14 @@ wrong_comparators = [
 ]
 
 
+def _get_error_state(code, proposed):
+    if 'assert ' in code:
+        assert FalsyConstantCompareViolation in proposed
+        proposed.remove(FalsyConstantCompareViolation)
+        return proposed
+    return proposed
+
+
 @pytest.mark.parametrize('comparators', wrong_comparators)
 def test_falsy_constant(
     assert_errors,
@@ -30,12 +38,16 @@ def test_falsy_constant(
     default_options,
 ):
     """Testing that compares with falsy constants are not allowed."""
-    tree = parse_ast_tree(eq_conditions.format(*comparators))
+    code = eq_conditions.format(*comparators)
+    tree = parse_ast_tree(code)
 
     visitor = WrongConstantCompareVisitor(default_options, tree=tree)
     visitor.run()
 
-    assert_errors(visitor, [FalsyConstantCompareViolation])
+    assert_errors(
+        visitor,
+        _get_error_state(code, [FalsyConstantCompareViolation]),
+    )
 
 
 @pytest.mark.filterwarnings('ignore::SyntaxWarning')
@@ -48,15 +60,19 @@ def test_falsy_constant_is(
     default_options,
 ):
     """Testing that compares with falsy constants are not allowed."""
-    tree = parse_ast_tree(is_conditions.format(*comparators))
+    code = is_conditions.format(*comparators)
+    tree = parse_ast_tree(code)
 
     visitor = WrongConstantCompareVisitor(default_options, tree=tree)
     visitor.run()
 
-    assert_errors(visitor, [
-        FalsyConstantCompareViolation,
-        WrongIsCompareViolation,
-    ])
+    assert_errors(
+        visitor,
+        _get_error_state(code, [
+            FalsyConstantCompareViolation,
+            WrongIsCompareViolation,
+        ]),
+    )
 
 
 @pytest.mark.parametrize('comparators', wrong_comparators)