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


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


Below are two Python scripts implementing tests with subtle differences.

def func(x):
    return x + 1
def test_answer():
    assert func(3) == 5
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 and generating the JUnit XML report (e.g., py-results1.xml), it can be imported to Xray (either by the REST API or through the 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".