diff --git a/bandit/core/manager.py b/bandit/core/manager.py index 956d0673b..e0309196d 100644 --- a/bandit/core/manager.py +++ b/bandit/core/manager.py @@ -264,9 +264,11 @@ def _parse_file(self, fname, fdata, new_files_list): lines = data.splitlines() self.metrics.begin(fname) self.metrics.count_locs(lines) - if self.ignore_nosec: - nosec_lines = set() - else: + + nosec_lines = set() + has_nosec = b'nosec' in data + + if not self.ignore_nosec and has_nosec: try: fdata.seek(0) if six.PY2: diff --git a/tests/functional/test_runtime.py b/tests/functional/test_runtime.py index b77a606b9..d581c7109 100644 --- a/tests/functional/test_runtime.py +++ b/tests/functional/test_runtime.py @@ -5,7 +5,6 @@ import os import subprocess -import six import testtools @@ -103,12 +102,7 @@ def test_example_nonsense2(self): ) self.assertEqual(0, retcode) self.assertIn("Files skipped (1):", output) - if six.PY2: - self.assertIn("nonsense2.py (exception while scanning file)", - output) - else: - self.assertIn("nonsense2.py (syntax error while parsing AST", - output) + self.assertIn("nonsense2.py (exception while scanning file)", output) def test_example_imports(self): (retcode, output) = self._test_example(['bandit', ], ['imports.py', ])