3.12. Step - 08 : Catalog of documented steps

If we have added more documentation in features/steps/*.py, e.g.

# features/steps/steps_addition.py

"""
Addition of numbers
=====================

Depends on ``libmath`` to do addition.

"""

from behave import given, when, then

@given(u"I have '{num1:d}' and '{num2:d}'")
def given_i_have(context, num1, num2):
    """ We store ``num1`` and ``num2`` from context.math

    Inputs:
        - num1 : Any number
        - num2 : Any number

    """
    context.math.doStoreNum1Num2(num1, num2)


@when(u"I add them")
def when_i_add(context):
    """ We add ``num1`` and ``num2`` of ``context.math`` """
    context.math.doAdd()

@then(u"The result must be '{value:d}'")
def then_the_result_must_be(context, value):
    """ We ensure expected value matches value returned by ``context.math`` """
    actual_value = context.math.getValue()
    assert value == actual_value, "Expected %d got %d"%(value, actual_value)

behave shows the catalog with documentation with this command:

behave --no-color --format steps.catalog --dry-run --no-summary

The catalog looks as below:

Given I have '{num1:d}' and '{num2:d}'
  Location: features/steps/steps_addition.py:13
    We store ``num1`` and ``num2`` from context.math
    
    Inputs:
        - num1 : Any number
        - num2 : Any number

When I add them
  Location: features/steps/steps_addition.py:25
    We add ``num1`` and ``num2`` of ``context.math``

Then The result must be '{value:d}'
  Location: features/steps/steps_addition.py:30
    We ensure expected value matches value returned by ``context.math``


3.13. Changes

In order to create good documentation, we have added comments in the python code. As compared to previous section Step - 06 : Hooks, the changes in files is:

Files old/features/environment.py and new/features/environment.py are identical
Files old/features/simple-addition.feature and new/features/simple-addition.feature are identical
diff '--unified=3' --new-file --ignore-all-space --text --recursive --show-c-function --report-identical-files old/features/steps/steps_addition.py new/features/steps/steps_addition.py
--- old/features/steps/steps_addition.py	2022-12-11 00:00:00.000000000 +0530
+++ new/features/steps/steps_addition.py	2022-12-11 00:00:00.000000000 +0530
@@ -1,18 +1,34 @@
 # features/steps/steps_addition.py
 
+"""
+Addition of numbers
+=====================
+
+Depends on ``libmath`` to do addition.
+
+"""
+
 from behave import given, when, then
 
 @given(u"I have '{num1:d}' and '{num2:d}'")
 def given_i_have(context, num1, num2):
+    """ We store ``num1`` and ``num2`` from context.math
+
+    Inputs:
+        - num1 : Any number
+        - num2 : Any number
+
+    """
     context.math.doStoreNum1Num2(num1, num2)
 
 
 @when(u"I add them")
 def when_i_add(context):
+    """ We add ``num1`` and ``num2`` of ``context.math`` """
     context.math.doAdd()
 
 @then(u"The result must be '{value:d}'")
 def then_the_result_must_be(context, value):
+    """ We ensure expected value matches value returned by ``context.math`` """
     actual_value = context.math.getValue()
     assert value == actual_value, "Expected %d got %d"%(value, actual_value)
-
Files old/features/table-addition.feature and new/features/table-addition.feature are identical
Files old/libmath.py and new/libmath.py are identical

Generated documentation is in next section Step - 09 : Sphinx.