{"id":4364,"date":"2016-07-19T01:04:05","date_gmt":"2016-07-19T05:04:05","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=4364"},"modified":"2018-04-03T10:37:24","modified_gmt":"2018-04-03T14:37:24","slug":"how-to-investigate-pytest-warnings","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/how-to-investigate-pytest-warnings\/","title":{"rendered":"How to investigate pytest-warnings"},"content":{"rendered":"<p>We recently integrated pytest, a Pythonic test runner, with our framework. After the tests were executed, pytest threw a couple of warnings.<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings-10.png\" data-rel=\"lightbox-image-0\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings-10.png\" alt=\"pytest_warnings\" width=\"685\" height=\"329\" class=\"aligncenter size-full wp-image-4402\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings-10.png 685w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings-10-300x144.png 300w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/a><br \/>\nWe decided to share our findings as the Google search results to debug the pytest-warnings were not quite revealing.<br \/>\n<strong>Solution:<\/strong> Use the<code>py.test -r w<\/code>command to gather additional information about the warnings.<\/p>\n<hr>\n<h3>Reporting in pytest:<\/h3>\n<p>The <code>py.test<\/code> command runs the tests and displays a test summary. For a more comprehensive report use the <code>-r<\/code> reporting command line option with pytest.<br \/>\nThe -r option can be used to show some extra summary specified by the character following it.<\/p>\n<pre lang=\"bash\" lines=\"false\">\r\n  -r chars              show extra test summary info as specified by chars\r\n                        (f)ailed, (E)error, (s)skipped, (x)failed, (X)passed\r\n                        (w)pytest-warnings (p)passed, (P)passed with output,\r\n                        (a)all except pP.\r\n<\/pre>\n<p>So if you were interested in investigating only failures, use <code>-r f<\/code> as a command line parameter.<\/p>\n<hr>\n<h3>What triggered those pytest-warnings?<\/h3>\n<p><a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings_verbose.png\" data-rel=\"lightbox-image-1\" data-rl_title=\"\" data-rl_caption=\"\" title=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings_verbose.png\" alt=\"pytest_warnings_verbose\" width=\"1237\" height=\"342\" class=\"aligncenter size-full wp-image-4380\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings_verbose.png 1237w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings_verbose-300x83.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings_verbose-768x212.png 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2016\/07\/pytest_warnings_verbose-1024x283.png 1024w\" sizes=\"auto, (max-width: 1237px) 100vw, 1237px\" \/><\/a><br \/>\nWhen you run the <code>py.test<\/code> command, pytest scours through the root directory and its sub-directories looking for files:<br \/>\na. Test files start with <code>test_*.py<\/code> or end with <code> *_test.py<\/code><br \/>\nb. Test classes prefixed with <code>Test<\/code> that have no<code> __init__ <\/code>method<br \/>\nc. Test functions prefixed with <code>test_<\/code><br \/>\npytest ignores files that has a class with a <code>__init__<\/code>method in them but it responsibly throws a warning about ignoring the file when it follows the pytest naming convention. In our case, we have two files in our framework that begin with <code>Test_<\/code> but have <code>__init__<\/code> method in them. Mystery solved!<\/p>\n<hr>\n<p>Now that you know how to read through the pytest-warnings try out the other command line options in pytest. Use the <code>py.test -h<\/code> command to know the list of command line options available.<\/p>\n<p><strong>If you liked this article, learn more <a href=\"https:\/\/qxf2.com\/blog\/about-qxf2\/\">about Qxf2&#8217;s<\/a> testing services for startups.<\/strong><\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>We recently integrated pytest, a Pythonic test runner, with our framework. After the tests were executed, pytest threw a couple of warnings. We decided to share our findings as the Google search results to debug the pytest-warnings were not quite revealing. Solution: Use thepy.test -r wcommand to gather additional information about the warnings. Reporting in pytest: The py.test command runs [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107,18],"tags":[],"class_list":["post-4364","post","type-post","status-publish","format-standard","hentry","category-pytest","category-python"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/4364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=4364"}],"version-history":[{"count":51,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/4364\/revisions"}],"predecessor-version":[{"id":4468,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/4364\/revisions\/4468"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=4364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=4364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=4364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}