I write test functions. In the docstring, I usually mention test case name as the summary line. The test case description follows that. Now I just need to fetch the test case name (first line) from docstring. Is there any pythonic way to do it?
def test_filesystem_001():
"""This is test case name of test_filesystem_001.
[Test Description]
-Create a file
-write some data
-delete it
"""
pass
So I need a way here just to print the first line of the docstring, i.e., "This is test case name of test_filesystem_001." Thanks in advance.
Just getting the first line:
>>>test_filesystem_001.__doc__.split("\n")[0]
This is test case name of test_filesystem_001.
You split
the __doc__
string at a new line. This returns an array of the part before the new line and the part after the new line. To access the first part use [0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With