1

I have a pytest module with the below test functions with doc strings, then when I run the pytest , I want the doc string to be displayed in the command line for each test run so that it will have clear view of the test case. eg:-

test_module.py:-

def test_add():
    '''
    This is a test function for adding two numbers
    '''
    expected_ouput= 10
    actual_output = x.add(1,9)

    assert expected_output == actual_output

def test_sub():
    '''
    This is a test function for subtracting two numbers
    '''
    expected_ouput= 1
    actual_output = x.sub(1,9)

    assert expected_output == actual_output 


>pytest 

Output:-

====================================================================== test session starts =======================================================================
platform darwin -- Python 3.6.4, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
rootdir: /Users/deepak/PycharmProjects/test_projects, inifile:
collected 3 items

tests/test_module.py .
--
test_add
This is a test  function for adding two numbers                                                                                                                            [ 33%]
--

test_sub
This is a test function for subtracting two numbers
                                                                                                             [100%]

=================================================================== 2 passed in 19.78 seconds ====================================================================

How to do this ?

dks551
  • 1,113
  • 1
  • 15
  • 39
  • This is interesting. I wonder if that is even possible. you can use print() though. – mad_ Jul 05 '18 at 14:48

1 Answers1

0

I don't use pytest, I use uinttest2 but this seems like it should work:

def test_blah():
    '''This is test blah'''
    print test_blah.__doc__

test_blah()

Also, most of these unit test tools provide a standard output format that third party apps use to display what test is being run (e.g. pyunit under eclipse IDE) so maybe run your tests with one of those third party tools.

shrewmouse
  • 5,338
  • 3
  • 38
  • 43