How to add values from test steps in pytest excel report

George Fischhof george at fischhof.hu
Mon Apr 30 05:09:45 EDT 2018


On 27 Apr 2018 9:49 am, "Sum" <sjsumitj at gmail.com> wrote:

Hi,

I am using python 2.7 and pytest version 3.2.1
I am using pytest excel plugin to run the pytest and generate test report
in excel format.

Step to install pytest excel : pip install pytest-excel

I am running my pytest test using below :

py.test --excelreport=report.xls e_test.py

Output Test report excel format :

SUITE NAME  TEST NAME   DESCRIPTION RESULT  DURATION    MESSAGE FILE
NAME   MARKERSTestSumFlow test_step1      PASSED  15.24737811
e_test.py

My query is that I want to display the values from my corresponding test
steps in pytest.
e.g. if my test step is following, then how do I display the output of
test_step1 "newNum" in the excel report.

def test_step1(fNum, sNum):
    newNum = fNum - sNum
    print newNum


Regards,
Sumit
-- 
https://mail.python.org/mailman/listinfo/python-list



Hi Sumit,

You should use assert for testing:
assert new_num == f_num - s_num, "Message if assert is false"

or if you want to use more checking, you should use pytest.assume plugin.

If you just want to write something to output, you should use logging, here
are some info about logging in pytest:
https://docs.pytest.org/en/latest/logging.html


BR,
George



More information about the Python-list mailing list