You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Overview

In this tutorial, we will create some tests in Python, using pytest.

Requirements

  • Install the Python "pip"
  • Install "pytest"
 pip install -U pytest

 

Description

Bellow, you can find two Python scripts implementing tests in subtle different ways.

test_sample.py
def func(x):
    return x + 1
def test_answer():
    assert func(3) == 5
test_class.py
class TestClass:
    def test_one(self):
        x = "this"
        assert 'h' in x
    def test_two(self):
        x = "hello"
        assert hasattr(x, 'check')

 

After running the tests (see bellow) and generating the JUnit XML report (e.g. py-results1.xml), it can be imported to Xray (either by the REST API or through "Import Execution Results" action within the Test Execution).

pytest --junitxml=py-results1.xml

 

JUnit's Test Case is mapped to a Generic Test in JIRA, and the "Generic Test Definition" field contains "pytest" concatenated with the name of the method that implements the test case.

The Execution Details of the Generic Test contains information about the Test Suite, which in this case corresponds to "pytest".

 

References

 

  • No labels