0

I searched and searched for a solution where I can use Sphinx autodoc to find all the decorator wrapped functions in my Python script/file. The script contains a number of functions all called step_impl with different parameters, but each wrapped by a different unique decorator. I want to be able to document these as separate functions. Currently it is only picking the last function in the script.

Here is what the script looks like:

@given(u'I am testing a browser')
def step_impl(context):
    """STEP: I am testing a browser
    :param context: webdriver context
    :type context: dictionary
    """
    <stuff here>

@when(u'I visit "{browser_page}"')
def step_impl(context, browser_page):
    <other stuff here>

@then(u'I see the Top Rail')
def step_impl(context):
    context.page.assert_element_display("id", "adv_header")
    <still other stuff here>

So I have the .rst file with the automodule formatting:

.. automodule:: features.steps.general
    :members:
    :undoc-members:
    :show-inheritance:

And the documentation only lists one function as:

features.steps.general.step_impl(context, title_text, element_type, element_name)

which happens to be the last function in the script.

How can I have the decorator listed for each function and list all functions even if they have the same name. I tried to understand functools.wraps, but couldn't get my head 'wrapped' around it (see what I did there!!).

Thank you for any guidance in advance....

bad_coder
  • 11,289
  • 20
  • 44
  • 72
simi
  • 1,535
  • 3
  • 12
  • 14
  • 2
    IMHO you should not have multiple functions with the same name and I doubt Sphinx can handle it "correclty". If your functions do different stuff, they should have different names. If they do the same thing, you should not have multiple functions. – Tryph Oct 07 '16 at 11:13
  • I am using Behave which is how it setups up the steps within the framework. – simi Oct 11 '16 at 18:32
  • 1
    I just took a look at the Behave documentation and the examples all use "step_impl" as function name, howeverI don't think it is a requirement. I think you can call the function as you wish. You should try. – Tryph Oct 12 '16 at 07:09
  • @Tryph Hmmm.... never thought of that. I will try that, thank you. – simi Oct 13 '16 at 13:38
  • In Behave you don't have to use 'step_impl' as a function name. Just use normal function naming convention. For better support in any IDE just use prefixes and descriptive name like: "@given(u'I am testing a browser')" use "def given_i_am_testing_a_browser". – maQ Mar 22 '17 at 13:40

0 Answers0