How to use _should_report method in pytest-cov

Best Python code snippet using pytest-cov

directors_test.py

Source:directors_test.py Github

copy

Full Screen

...104 else:105 code = None106 self._director = directors.Director(107 src_tree, self._errorlog, _TEST_FILENAME, disable, code)108 def _should_report(self, expected, lineno, error_name="test-error",109 filename=_TEST_FILENAME):110 error = errors.Error.for_test(111 errors.SEVERITY_ERROR, "message", error_name, filename=filename,112 lineno=lineno)113 self.assertEqual(114 expected,115 self._director.filter_error(error))116class DirectorTest(DirectorTestCase):117 def test_ignore_globally(self):118 self._create("", ["my-error"])119 self._should_report(False, 42, error_name="my-error")120 def test_ignore_one_line(self):121 self._create("""122 # line 2123 x = 123 # type: ignore124 # line 4125 """)126 self._should_report(True, 2)127 self._should_report(False, 3)128 self._should_report(True, 4)129 def test_ignore_one_line_mypy_style(self):130 self._create("""131 # line 2132 x = 123 # type: ignore[arg-type]133 # line 4134 """)135 self._should_report(True, 2)136 self._should_report(False, 3)137 self._should_report(True, 4)138 def test_utf8(self):139 self._create("""140 x = u"abc□def\\n"141 """)142 def test_ignore_extra_characters(self):143 self._create("""144 # line 2145 x = 123 # # type: ignore146 # line 4147 """)148 self._should_report(True, 2)149 self._should_report(False, 3)150 self._should_report(True, 4)151 def test_ignore_until_end(self):152 self._create("""153 # line 2154 # type: ignore155 # line 4156 """)157 self._should_report(True, 2)158 self._should_report(False, 3)159 self._should_report(False, 4)160 def test_out_of_scope(self):161 self._create("""162 # type: ignore163 """)164 self._should_report(False, 2)165 self._should_report(True, 2, filename=None) # No file.166 self._should_report(True, 2, filename="some_other_file.py") # Other file.167 self._should_report(False, None) # No line number.168 self._should_report(False, 0) # line number 0.169 def test_disable(self):170 self._create("""171 # line 2172 x = 123 # pytype: disable=test-error173 # line 4174 """)175 self._should_report(True, 2)176 self._should_report(False, 3)177 self._should_report(True, 4)178 def test_disable_extra_characters(self):179 self._create("""180 # line 2181 x = 123 # # pytype: disable=test-error182 # line 4183 """)184 self._should_report(True, 2)185 self._should_report(False, 3)186 self._should_report(True, 4)187 def test_disable_until_end(self):188 self._create("""189 # line 2190 # pytype: disable=test-error191 # line 4192 """)193 self._should_report(True, 2)194 self._should_report(False, 3)195 self._should_report(False, 4)196 def test_enable_after_disable(self):197 self._create("""198 # line 2199 # pytype: disable=test-error200 # line 4201 # pytype: enable=test-error202 """)203 self._should_report(True, 2)204 self._should_report(False, 3)205 self._should_report(False, 4)206 self._should_report(True, 5)207 self._should_report(True, 100)208 def test_enable_one_line(self):209 self._create("""210 # line 2211 # pytype: disable=test-error212 # line 4213 x = 123 # pytype: enable=test-error214 """)215 self._should_report(True, 2)216 self._should_report(False, 3)217 self._should_report(False, 4)218 self._should_report(True, 5)219 self._should_report(False, 6)220 self._should_report(False, 100)221 def test_disable_other_error(self):222 self._create("""223 # line 2224 x = 123 # pytype: disable=test-other-error225 # line 4226 """)227 self._should_report(True, 2)228 self._should_report(True, 3)229 self._should_report(False, 3, error_name="test-other-error")230 self._should_report(True, 4)231 def test_disable_multiple_error(self):232 self._create("""233 # line 2234 x = 123 # pytype: disable=test-error,test-other-error235 # line 4236 """)237 self._should_report(True, 2)238 self._should_report(False, 3)239 self._should_report(False, 3, error_name="test-other-error")240 self._should_report(True, 4)241 def test_disable_all(self):242 self._create("""243 # line 2244 x = 123 # pytype: disable=*245 # line 4246 """)247 self._should_report(True, 2)248 self._should_report(False, 3)249 self._should_report(True, 4)250 def test_multiple_directives(self):251 self._create("""252 x = 123 # sometool: directive=whatever # pytype: disable=test-error253 """)254 self._should_report(False, 2)255 def test_error_at_line_0(self):256 self._create("""257 x = "foo"258 # pytype: disable=attribute-error259 """)260 self._should_report(False, 0, error_name="attribute-error")261 def test_disable_without_space(self):262 self._create("""263 # line 2264 x = 123 # pytype:disable=test-error265 # line 4266 """)267 self._should_report(True, 2)268 self._should_report(False, 3)269 self._should_report(True, 4)270 def test_invalid_disable(self):271 def check_warning(message_regex, text):272 self._create(text)273 self.assertLessEqual(1, len(self._errorlog))274 error = list(self._errorlog)[0]275 self.assertEqual(_TEST_FILENAME, error._filename)276 self.assertEqual(1, error.lineno)277 self.assertRegex(str(error), message_regex)278 check_warning("Unknown pytype directive.*disalbe.*",279 "# pytype: disalbe=test-error")280 check_warning("Invalid error name.*bad-error-name.*",281 "# pytype: disable=bad-error-name")282 check_warning("Invalid directive syntax",283 "# pytype: disable")...

Full Screen

Full Screen

meta_tags.py

Source:meta_tags.py Github

copy

Full Screen

...66 elif word in attr_value:67 where = self.ATTR_VALUE68 content = attr_value69 # Now... if we found something, report it =)70 if self._should_report(attr_name, attr_value, where):71 # The attribute is interesting!72 fmt = 'The URI: "%s" sent a <meta> tag with attribute'\73 ' %s set to "%s" which looks interesting.'74 desc = fmt % (response.get_uri(), where, content)75 tag_name = self._find_name(tag)76 if self.INTERESTING_WORDS.get(tag_name, None):77 usage = self.INTERESTING_WORDS[tag_name]78 desc += ' The tag is used for %s.' % usage79 80 i = Info('Interesting META tag', desc, response.id,81 self.get_name())82 i.set_uri(response.get_uri())83 i.add_to_highlight(where, content)84 self.kb_append_uniq(self, 'meta_tags', i, 'URL')85 def _should_report(self, key, value, where):86 """87 :param key: The meta tag attribute name88 :param value: The meta tag attribute value89 :param where: The location (key|value) that we found interesting90 :return: True if we should report this information91 """92 if where is None:93 return False94 return True95 def _find_name(self, tag):96 """97 :return: the tag name.98 """99 for key, value in tag.items():...

Full Screen

Full Screen

reportengine.py

Source:reportengine.py Github

copy

Full Screen

...29 if self._fname is None:30 return False31 if not os.path.exists(self._get_file_path()):32 return False33 return self._should_report()34 def _should_report(self):35 return False36 def get_report(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-cov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful