Skip to content

Add related and details.rst to 'redundant-unittest-assert' style message's doc #6483

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/data/messages/r/redundant-unittest-assert/bad.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
class DummyTestCase(unittest.TestCase):
def test_dummy(self):
self.assertTrue("foo") # [redundant-unittest-assert]


def test_division():
a = 9 / 3
assert "No ZeroDivisionError were raised" # assert-on-string-literal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding an example for another message here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added an example expecting this code to raise a [redundant-unittest-assert], but I think those two messages should be the same one. I think it can illustrate the two ways to fix the issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this example is about unittest assertions, not normal assert. I don't think we should merge those.

3 changes: 2 additions & 1 deletion doc/data/messages/r/redundant-unittest-assert/details.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Directly asserting a string literal will always pass.
Directly asserting a string literal will always pass. The solution is to
test something that could fail, or not assert at all.
8 changes: 6 additions & 2 deletions doc/data/messages/r/redundant-unittest-assert/good.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@

class DummyTestCase(unittest.TestCase):
def test_dummy(self):
actual = "test_result"
self.assertEqual(actual, "expected")
# Nothing, as an assert of a string literal will always pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually kind of like the current example. I think the comment works nicely in details.rst.

pass

def test_division():
a = 9 / 3
assert a == 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do # nothing above we should also do so here? Note, I actually think we should keep the code instead of the comment.

3 changes: 3 additions & 0 deletions doc/data/messages/r/redundant-unittest-assert/related.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- `Tests without assertion <https://stackoverflow.com/a/137418/2519059>`_
- `Testing that there is no error raised <https://stackoverflow.com/questions/20274987>`_
- `Parametrizing conditional raising <https://docs.pytest.org/en/latest/example/parametrize.html#parametrizing-conditional-raising>`_