|
| 1 | +=================== |
| 2 | +agent-python-pytest |
| 3 | +=================== |
| 4 | + |
| 5 | + |
| 6 | +**Important:** this is draft version under development. |
| 7 | + |
| 8 | +Pytest plugin for reporting test results of Pytest to the 'Reportal Portal'. |
| 9 | + |
| 10 | +Usage |
| 11 | +----- |
| 12 | + |
| 13 | +Installation |
| 14 | +~~~~~~~~~~~~ |
| 15 | + |
| 16 | +To install pytest plugin execute next command in a terminal: |
| 17 | + |
| 18 | +.. code-block:: bash |
| 19 | +
|
| 20 | + pip install pytest-reportportal |
| 21 | +
|
| 22 | +
|
| 23 | +Configuration |
| 24 | +~~~~~~~~~~~~~ |
| 25 | + |
| 26 | +Prepare the config file :code:`pytest.ini` in root directory of tests or specify |
| 27 | +any one using pytest command line option: |
| 28 | + |
| 29 | +.. code-block:: bash |
| 30 | +
|
| 31 | + py.test -c config.cfg |
| 32 | +
|
| 33 | +
|
| 34 | +The :code:`pytest.ini` file should have next mandatory fields: |
| 35 | + |
| 36 | +- :code:`rp_uuid` - number could be found in the User profile section |
| 37 | +- :code:`rp_project` - name of project in Report Potal |
| 38 | +- :code:`rp_endpoint` - address of Report Portal Server |
| 39 | + |
| 40 | +Example of :code:`pytest.ini`: |
| 41 | + |
| 42 | +.. code-block:: text |
| 43 | +
|
| 44 | + [pytest] |
| 45 | + rp_uuid = fb586627-32be-47dd-93c1-678873458a5f |
| 46 | + rp_endpoint = http://192.168.1.10:8080 |
| 47 | + rp_project = user_personal |
| 48 | + rp_launch_tags = 'PyTest' 'Smoke' |
| 49 | +
|
| 50 | +Also launch tags could be added, but this parapmeter is not |
| 51 | +mandatory :code:`rp_launch_tags = 'PyTest' 'Report_Portal'`. |
| 52 | + |
| 53 | + |
| 54 | +Logging |
| 55 | +~~~~~~~ |
| 56 | + |
| 57 | +For logging of the test item flow to Report Portal, please, use the python |
| 58 | +logging handler privided by plugin like bellow: |
| 59 | + |
| 60 | +.. code-block:: python |
| 61 | +
|
| 62 | + # Import Report Portal handler in the test module. |
| 63 | + from pytest_reportportal import RPlogHandler |
| 64 | + # Get logger. |
| 65 | + logger = logging.getLogger() |
| 66 | + # Create hanler, set log level add it to the logger. |
| 67 | + rp_handler = RPlogHandler() |
| 68 | + rp_handler.setLevel(logging.INFO) |
| 69 | + logger.addHandler(rp_handler) |
| 70 | + # In this case only INFO messages will be sent to the Report Portal. |
| 71 | + def test_one(self): |
| 72 | + logger.info("Case1. Step1") |
| 73 | + x = "this" |
| 74 | + logger.info("Case1. Step2") |
| 75 | + assert 'h' in x |
| 76 | +
|
| 77 | +
|
| 78 | +Launching |
| 79 | +~~~~~~~~~ |
| 80 | + |
| 81 | +To run test with Report Portal you need to specify neme of :code:`launch`: |
| 82 | + |
| 83 | +.. code-block:: bash |
| 84 | +
|
| 85 | + py.test ./tests --rp-launch AnyLaunchName |
| 86 | +
|
| 87 | +
|
| 88 | +Copyright Notice |
| 89 | +---------------- |
| 90 | + |
| 91 | +Licensed under the GPLv3_ license (see the LICENSE file). |
| 92 | + |
| 93 | +.. _GPLv3: https://www.gnu.org/licenses/quick-guide-gplv3.html |
0 commit comments