Package: qase-pytest
QasePytest PluginInstallationpip install qase-pytestUpgrade from 4.x to 5.xA new version of qase-pytest reporter has breaking changes. Follow theseguidethat will help you to migrate to a new version.ConfigurationQase Pytest Plugin can be configured in multiple ways:using a config fileqase.config.jsonusing environment variablesusing CLI optionsAll configuration options are listed in the following doc:Configuration.Example: qase.config.json{
	"mode": "testops", 
	"fallback": "report",
	"report": {
		"driver": "local",
		"connection": {
			"local": {
				"path": "./build/qase-report",
				"format": "json" 
			}
		}
	},
	"testops": {
		"bulk": true,
		"api": {
			"token": "YOUR_API_TOKEN",
			"host": "qase.io"
		},
		"run": {
            "id": 1,
			"title": "Test run title",
			"complete": true
		},
        "plan": {
            "id": 1
        },
		"defect": true,
		"project": "YOUR_PROJECT_CODE",
		"chunk": 200
	},
	"framework": {
		"pytest": {
			"capture": {
				"logs": true,
				"http": true
			}
		}
	},
	"environment": "local"
}UsageLink tests with test cases in Qase TestOpsTo link tests in code with tests in Qase TestOps you can use predefined decorators:fromqaseio.pytestimportqase@qase.id(13)@qase.title("My first test")@qase.fields(("severity","critical"),("priority","hight"),("layer","unit"),("description","Try to login in Qase TestOps using login and password"),("description","*Precondition 1*. Markdown is supported."),)deftest_example_1():passEach unique number can only be assigned once to the class or function being used.Ignore a particular testIf you want to exclude a particular test from the report, you can use the@qase.ignoredecorator:fromqaseio.pytestimportqase@qase.ignoredeftest_example_1():passPossible test result statusesPASSED - when test passedFAILED - when test failed with AssertionErrorBLOCKED - when test failed with any other exceptionSKIPPED - when test has been skippedCapture network logsIn order to capture network logs, you need to enable thehttpoption in thecapturesection of theframeworksection in the config file.Qase Pytest reporter will capture all requests and responses and save as a test step automatically.Add attachments to test resultsWhen you need to push some additional information to server you could use
attachments:importpytestfromqaseio.pytestimportqase@pytest.fixture(scope="session")defdriver():driver=webdriver.Chrome()yielddriverlogs="\n".join(str(row)forrowindriver.get_log('browser')).encode('utf-8')qase.attach((logs,"text/plain","browser.log"))driver.quit()@qase.title("My first test")deftest_example_1():qase.attach("/path/to/file","/path/to/file/2")qase.attach(("/path/to/file/1","application/json"),("/path/to/file/3","application/xml"),)@qase.id(12)deftest_example_2(driver):qase.attach((driver.get_screenshot_as_png(),"image/png","result.png"))You could pass as much files as you need.Also you should know, that if no case id is associated with current test in
pytest - attachment would not be uploaded:importpytestfromqaseio.pytestimportqase@pytest.fixture(scope="session")defdriver():driver=webdriver.Chrome()yielddriverlogs="\n".join(str(row)forrowindriver.get_log('browser')).encode('utf-8')# This would do nothing, because last test does not have case id linkqase.attach((logs,"text/plain","browser.log"))driver.quit()deftest_example_2(driver):# This would do nothingqase.attach((driver.get_screenshot_as_png(),"image/png","result.png"))Linking code with stepsIt is possible to link test step with function, or using context.fromqaseio.pytestimportqase@qase.step("First step")# test step namedefsome_step():sleep(5)@qase.step("Second step")# test step namedefanother_step():sleep(3)...deftest_example():some_step()another_step()# test step hashwithqase.step("Third step"):sleep(1)Sending tests to existing testrunTestrun in TestOps will contain only those test results, which are presented in testrun,
but every test would be executed.pytest\--qase-mode=testops\--qase-testops-api-token=<yourapitokenhere>\--qase-testops-project=PRJCODE\# project, where your testrun exists in--qase-testops-run-id=3# testrun idCreating test run base on test plan (selective launch)Create new testrun base on testplan. Testrun in Qase TestOps will contain only those
test results.qase-pytestsupports selective executionpytest\--qase-mode=testops\--qase-testops-api-token=<yourapitokenhere>\--qase-testops-project=PRJCODE\# project, where your testrun exists in--qase-testops-plan-id=3# testplan idCreating new testrun according to current pytest runIf you want to create a new test run in Qase TestOps for each execution, you can simply
skip--qase-testops-runoption. If you want to provide a custom name for this run, you can add an
option--qase-testops-run-titlepytest\--qase-mode=testops\--qase-testops-api-token=<yourapitokenhere>\--qase-testops-project=PRJCODE\# project, where your testrun would be created--qase-testops-run-title=My\First\Automated\Run