Package: pytest-qaseio
pytest-qaseioAnother implementation of Pytest plugin for Qase.io integrationOur features:Extended error report for Selenium (screenshot, html and browser logs)Strict case ids validationsInstead of case ids, it uses direct links to casesCustom file storage for attachmentsProvide URL of test run starterMost of configuration options use environment variablesNot supported currently:Adding results to existing test runsTest stepsInstallationpipinstallpytest-qaseioConfigurationTo work with plugin you have to provide the following environment variables:QASE_PROJECT_CODE- Code of your Qase.io projectQASE_TOKEN- API token to interact with Qase.io runs via APIA few more configuration environment variables are also available:QASE_PLAN_ID,QASE_ENVIRONMENT_IDandQASE_URL_CUSTOM_FIELD_ID.Specifying plan allows to create run "from template".
New run will contain all cases from plan + cases that specified in testsQASE_URL_CUSTOM_FIELD_IDandRUN_SOURCE_URLvariables allow to specify custom
field ID to store theURL of the run sourceUsageTo connect your python test withQase.iojust useqasemark and specify test case url:importpytest@pytest.mark.qase("https://app.qase.io/case/DEMO-1")deftest_demo():"""Check qaseio plugin works as expected."""Since this package is mostly used for selenium tests, you need to provide a
value for--webdriverflag. If you set--webdriver=remoteand want to specify
name of remote browser (not just Remote), use--remote-browserflag or set capabilities viavariables. This will be used in test run name and
in attachments path.To enable plugin use flag--qase-enabled.pytesttests/--qase-enabled--webdriver=chromeWork with SeleniumThis plugin expects to be used with selenium and provides additional debug
info from browser. To make it possible, prepare fixture that provides webdriver
and use the following snippet to set_webdriverattribute for each test:@pytest.fixture(autouse=True)defannotate_node_with_driver(self,request:SubRequest):"""Add webdriver instance to test, that later will be used to generate debug info.This fixture detects whether a test or its parent is using a selenium webdriver, and marksthe node with the webdriver instance."""forfixture_nameinrequest.fixturenames:iffixture_name.endswith("webdriver")andisinstance(request.getfixturevalue(fixture_name),selenium_webdriver.Remote,):request.node._webdriver=request.getfixturevalue(fixture_name)File storagepytest-qaseioplugin provides additional debug information in comment for
failed tests. It prepares browser log, html and screenshot. To store this
files plugin uses file storage. By default plugin provides and usesQaseFileStoragethat uploads files to Qase.io S3 bucket via attachments API.
If you don't want to upload files, just set--qase-file-storage=Noneoption.You can also provide your custom file storage. To do this, follow the next steps:Prepare object that implementssave_file_obj()method according tostorage.FileProtocolOverridepytest_qase_file_storageshook and add mapping to your storageUse--qase-file-storageoption to specify name of you storageNote: Keep in mind thatNonechoice is reserved for disabling storages.Example:## storages.pyclassS3FileStorage:def__init__(self,**credentials):...defsave_file_obj(self,content:bytes,filename:str,**kwargs)->str:"""Upload file to S3 and get it's url."""self.s3_client.put_object(Body=content,Bucket=self.bucket,Key=filename,**kwargs,)returnf"{self.s3_client.meta.endpoint_url}/{self.bucket}/{filename}"## conftest.py@pytest.hookimpl(tryfirst=True)defpytest_qase_file_storages()->dict[str,qase_storages.FileStorage]:"""Override file storages to use custom S3 bucket."""return{"s3":S3FSStorage(),}## Run tests$pytest--qase-enabled--qase-file-storage=s3You can also overrideqase_file_storageto set storage for part of tests
(or for all in globalconftests.py):@pytest.fixturedefqase_file_storage()->storage.FileProtocol:returnS3FileStorage()Pytest optionsPlugin provides two pytest options:--qase-enabled- use turn on qase plugin and run your tests with Qase.io integration--qase-file-storage- allows to choose storage to upload additional debug info for failed tests.Noneandqasechoices are available by default.Set run source urlSometimes it might be useful to see the source that runs tests. If you need this,
you have tocreate custom fieldfor your Qase.io project.Then you need to findIDof this field and setQASE_URL_CUSTOM_FIELD_IDenvironment variable.
To find custom field ID:open project ->Test runs->Start new test runinspect custom field section with browser dev toolsfind label or text area of this custom field and you will see id in next formatcf-1-31. The last number (31) is ID.Finally, provideRUN_SOURCE_URLenvironment variable with URL to test run.LicenseMIT