{"id":15338,"date":"2021-07-05T22:58:16","date_gmt":"2021-07-06T02:58:16","guid":{"rendered":"https:\/\/qxf2.com\/blog\/?p=15338"},"modified":"2021-07-05T22:58:16","modified_gmt":"2021-07-06T02:58:16","slug":"allure-integration-with-pytest","status":"publish","type":"post","link":"https:\/\/qxf2.com\/blog\/allure-integration-with-pytest\/","title":{"rendered":"Allure integration with pytest"},"content":{"rendered":"<p>Recently, I was on the lookout for a good open-source reporting tool other than the <a href=\"https:\/\/qxf2.com\/blog\/reportportal-integration-with-pytest\/\">ReportPortal<\/a> tool which we already integrated with pytest in the past. As a result, I came across a tool called <a href=\"https:\/\/docs.qameta.io\/allure\/\" rel=\"noopener\" target=\"_blank\">Allure<\/a>. When I started integrating allure with pytest, I stumbled upon a couple of errors as there was no straightforward guide to do so. Therefore, I am writing this blog post!!<\/p>\n<hr>\n<h3>What is Allure?<\/h3>\n<p>Allure framework is a lightweight test reporting tool that shows useful information about test execution in a neat web report form. It can be integrated with popular testing frameworks across languages. To know more about allure you can read through its <a href=\"https:\/\/docs.qameta.io\/allure\/\">documentation<\/a>.<\/p>\n<hr>\n<h3>Allure integration with pytest<\/h3>\n<h4> Creating a test<\/h4>\n<p>To illustrate how to integrate Allure with pytest, we will be making use of a simple python test that verifies the <a href=\"https:\/\/qxf2.com\/\">Qxf2<\/a> website&#8217;s title.<\/p>\n<pre lang=\"python\">\r\n\"\"\"\r\nThis script will open the Qxf2 website and verify its title\r\n\"\"\"\r\nfrom selenium import webdriver\r\n\r\nsite_url = 'https:\/\/qxf2.com\/'\r\n\r\ndef test_site_title():\r\n    \"Checks Qxf2's website title\"\r\n    driver = webdriver.Chrome()\r\n    driver.get(site_url)\r\n    assert driver.title == 'Qxf2 Services: Outsourced Software QA for startups'\r\n<\/pre>\n<h4>Allure Setup<\/h4>\n<ol>\n<li>Install <a href=\"https:\/\/pypi.org\/project\/allure-pytest\/\" rel=\"noopener\" target=\"_blank\">allure-pytest<\/a> python package with command <span style=\"color:orange;\">pip install allure-pytest<\/span><\/li>\n<li>Next, download the latest allure package zip file from the <a href=\"https:\/\/github.com\/allure-framework\/allure2\/releases\" rel=\"noopener\" target=\"_blank\">allure-framework GitHub repo<\/a>\n<ul>\n<li>Unzip the downloaded zip file<\/li>\n<li>Copy the path till bin<\/li>\n<li>Add it to the path environment variable<\/li>\n<\/ul>\n<\/li>\n<li>Open your terminal and run\n<pre lang=\"python\">allure --version<\/pre>\n<p> If you see the allure version printed then your setup is successful!!<\/li>\n<\/ol>\n<h4>Generating Allure report using pytest<\/h4>\n<ol>\n<li>In your project directory, you first need to generate a folder to save the allure reports, you can automatically generate this with a command\n<pre lang=\"python\">allure generate<\/pre>\n<p> This will create a folder named <span style=\"color:orange;\">allure-report<\/span> in your project directory.<\/li>\n<li>You are now set to run your test with pytest runner by specifying the directory path to save your allure report, for example :\n<pre lang=\"python\">pytest --alluredir=allure-report\/<\/pre>\n<p> Once test execution completes, all the test results would get stored in allure-report directory.<\/li>\n<li>You can now view the allure-report in the browser with the command &#8211;\n<pre lang=\"python\">allure serve allure-report\/<\/pre>\n<p> This will open up the report in your default browser automatically and would look like<br \/>\n<a href=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2021\/07\/allure-browser.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\/2021\/07\/allure-browser-300x144.png\" alt=\"allure-report\" width=\"300\" height=\"144\" class=\"aligncenter size-medium wp-image-15341\" srcset=\"https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2021\/07\/allure-browser-300x144.png 300w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2021\/07\/allure-browser-1024x492.png 1024w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2021\/07\/allure-browser-768x369.png 768w, https:\/\/qxf2.com\/blog\/wp-content\/uploads\/2021\/07\/allure-browser.png 1366w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<\/ol>\n<hr>\n<p>Let me know in the comments if this blog helped you to integrate your tests with Allure!!  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I was on the lookout for a good open-source reporting tool other than the ReportPortal tool which we already integrated with pytest in the past. As a result, I came across a tool called Allure. When I started integrating allure with pytest, I stumbled upon a couple of errors as there was no straightforward guide to do so. Therefore, [&hellip;]<\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[107],"tags":[],"class_list":["post-15338","post","type-post","status-publish","format-standard","hentry","category-pytest"],"_links":{"self":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/15338","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\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/comments?post=15338"}],"version-history":[{"count":17,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/15338\/revisions"}],"predecessor-version":[{"id":20227,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/posts\/15338\/revisions\/20227"}],"wp:attachment":[{"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/media?parent=15338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/categories?post=15338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qxf2.com\/blog\/wp-json\/wp\/v2\/tags?post=15338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}