Page History
...
In this tutorial, we will create some tests in Python , using pytest.
Requirements
- Install the Python "pip"
- Install "pytest"
No Format |
---|
pip install -U pytest" |
Description
Bellow, you can find Below are two Python scripts implementing tests in with subtle different waysdifferences.
Code Block | ||||
---|---|---|---|---|
| ||||
def func(x): return x + 1 def test_answer(): assert func(3) == 5 |
Code Block | ||||
---|---|---|---|---|
| ||||
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 "the Import Execution Results" action within the Test Execution).
No Format |
---|
pytest --junitxml=py-results1.xml |
...
JUnit's Test Case is mapped to a Generic Test in JIRAJira, 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
- http://docs.python-guide.org/en/latest/writing/tests/
- http://doc.pytest.org/en/latest/usage.html#creating-junitxml-format-files
...