{"id":84,"date":"2012-07-16T20:44:40","date_gmt":"2012-07-16T20:44:40","guid":{"rendered":"http:\/\/blog.mozilla.org\/webqa\/?p=84"},"modified":"2012-07-16T20:44:40","modified_gmt":"2012-07-16T20:44:40","slug":"setting-up-pycharm-to-run-mozwebqa-tests","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/fxtesteng\/2012\/07\/16\/setting-up-pycharm-to-run-mozwebqa-tests\/","title":{"rendered":"Setting Up PyCharm to Run MozWebQA Tests"},"content":{"rendered":"<p><em><strong>(The following is a guest post by <a href=\"http:\/\/www.silverwareconsulting.com\/\" target=\"_blank\">Bob Silverberg<\/a>, one of our awesome contributors in Web QA.)<\/em><\/strong><\/p>\n<p><a href=\"http:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a> is a Python IDE, released by <a href=\"http:\/\/www.jetbrains.com\/index.html\" target=\"_blank\">JetBrains<\/a>.  I quite enjoy using it and, as I&#039;ve recently started contributing some tests to Mozilla&#039;s <a href=\"https:\/\/quality.mozilla.org\/teams\/web-qa\/\" target=\"_blank\">Web QA<\/a> department (mozwebqa), I wanted to use it to interactively debug some mozwebqa tests. This turned out to be a lot trickier than I had imagined, so I am documenting the steps to do so via this post.<\/p>\n<p>This post assumes you have a project open in PyCharm for one of the mozwebqa projects. I am going to use <a href=\"https:\/\/github.com\/mozilla\/marketplace-tests\" target=\"_blank\">marketplace-tests<\/a> for this example.  As I am on a Mac, the instructions and screen shots will be OS X-specific, but I imagine they will translate pretty closely to Windows.<\/p>\n<h3>Step 1 &#8211; Configure py.test as your default test runner<\/h3>\n<ol>\n<li>Open up the <em>Preferences&#8230;<\/em> dialog and choose <em>Python Integrated Tools<\/em> under <em>Project Settings<\/em>.<\/li>\n<li>Choose <strong>py.test<\/strong> as the <em>Default test runner.<\/em><\/li>\n<li>Click <em>OK<\/em>.<\/li>\n<\/ol>\n<h3>Step 2 &#8211; Set default run configuration parameters for your project<\/h3>\n<ol>\n<li>Type <strong>ctrl + alt + R<\/strong> to open the <em>Run<\/em> configuration selector.<\/li>\n<li>Type <strong>0<\/strong>, or choose the first option (<em>Edit configurations&#8230;<\/em>) from the select list.<\/li>\n<li>In the <em>Run<\/em> dialog, expand <em>Defaults &gt; Python&#039;s test<\/em> and click on<em>py.test<\/em>.<\/li>\n<li>Make sure the Python interpreter that you want to use for this project is selected for <em>Python interpreter<\/em>.  If you are using virtualenv you may have to configure a new Python interpreter for your virtualenv. More on that in a separate post.<\/li>\n<li>Choose the root of your project for <em>Working directory<\/em>.<\/li>\n<li>Click <em>Apply<\/em>, then <em>Close<\/em>.<\/li>\n<\/ol>\n<h3>Step 3 &#8211; Create a pytest.ini file in the root of your project<\/h3>\n<p>This is necessary to pass command line options to py.test. It would be nice if there were a way to do this via the IDE, but I was not able to do it.  If anyone knows how, or can figure out how, to do that I&#039;d love to know. I <em>was<\/em> able to pass a single option to the command line from PyCharm, but could not get it to work with multiple options.<\/p>\n<ol>\n<li>Create a file called <em>pytest.ini<\/em> in the root of your project.<\/li>\n<li>Add the command line options you need into that file under the <em>[pytest]<\/em> section. See below for an example from <em>marketplace-tests.<\/em><\/li>\n<li>Click <em>OK<\/em>.<\/li>\n<\/ol>\n<p><code>[pytest]<br \/>\naddopts = --driver=firefox --credentials=mine\/credentials.yaml --destructive<\/code>\n<\/p>\n<h3>Step 4 &#8211; Create a copy of credentials.yaml in a personal folder<\/h3>\n<p>You are going to have to edit <em>credentials.yaml<\/em> to place some actual credentials in it, so in order to not have it overwitten each time you do a pull, you should put a copy that you are going to use somewhere else. I tend to create a <em>\/mine<\/em> folder under the project root and place it there, but you can put it anywhere you like. You will notice that the command line option above uses that <em>\/mine<\/em> folder to locate the credentials file.<\/p>\n<h3>Step 5 &#8211; Run your tests<\/h3>\n<p>With a file that contains tests open in an editor window, type <strong>ctrl + shift + R<\/strong> and PyCharm will run all of the tests in the file.  If you wish to run just one test, type <strong>ctrl + alt + R<\/strong>, followed by <strong>0<\/strong> to open the <em>Edit configurations&#8230;<\/em> dialog and then place the name of your test in the <em>Keywords<\/em> input. Click <strong>Run<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(The following is a guest post by Bob Silverberg, one of our awesome contributors in Web QA.) PyCharm is a Python IDE, released by JetBrains. I quite enjoy using it &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/fxtesteng\/2012\/07\/16\/setting-up-pycharm-to-run-mozwebqa-tests\/\">Read more<\/a><\/p>\n","protected":false},"author":512,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25202,25193],"tags":[25209,25208,19632],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts\/84"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/users\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/fxtesteng\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}