Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
Next Next commit
Make assertion in main test work
assert_called_with does the assertion. The function has return value
None. So don't assert assert_called_with.

Fixes the "This with: makes no sense" comment.
  • Loading branch information
bcaller authored and Ben Caller committed Jul 27, 2018
commit e2841be764ff563b4ace44c88dc1ecd138862372
20 changes: 8 additions & 12 deletions tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ def test_text_output(self, mock_text, mock_find_vulnerabilities, mock_parse_args
'parse_args is mocked'
])
assert mock_text.report.call_count == 1
# This with: makes no sense
with self.assertRaises(AssertionError):
assert mock_text.report.assert_called_with(
mock_find_vulnerabilities.return_value,
mock_parse_args.return_value.output_file
)
mock_text.report.assert_called_with(
mock_find_vulnerabilities.return_value,
mock_parse_args.return_value.output_file
)

@mock.patch('pyt.__main__.discover_files')
@mock.patch('pyt.__main__.parse_args')
Expand All @@ -54,12 +52,10 @@ def test_json_output(self, mock_json, mock_find_vulnerabilities, mock_parse_args
'parse_args is mocked'
])
assert mock_json.report.call_count == 1
# This with: makes no sense
with self.assertRaises(AssertionError):
assert mock_json.report.assert_called_with(
mock_find_vulnerabilities.return_value,
mock_parse_args.return_value.output_file
)
mock_json.report.assert_called_with(
Copy link
Copy Markdown
Collaborator

@KevinHock KevinHock Jul 27, 2018

Choose a reason for hiding this comment

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

You're my hero! :D
What was the bug? re: This with: makes no sense

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@KevinHock no, the function mock_text.report.assert_called_with() does the assertion - it either raises AssertionError or returns None.

Therefore, if you do assert mock_text.report.assert_called_with() it's like assert None.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wow πŸ€¦β€β™‚οΈ I must have had tunnel vision at the time. Thanks so much for fixing that πŸ˜„

mock_find_vulnerabilities.return_value,
mock_parse_args.return_value.output_file
)


class DiscoverFilesTest(BaseTestCase):
Expand Down