[pytest-dev] More flexibility on test function naming conventions

Bruno Oliveira nicoddemus at gmail.com
Sat Jan 9 08:41:06 EST 2016


Ernesto,

Nice that you found the solution. Just to note that the documentation seems
correct:

.. confval:: python_functions

   One or more name prefixes or glob-patterns determining which test
functions
   and methods are considered tests.

Cheers,
Bruno.


On Sat, Jan 9, 2016 at 8:16 AM Ernesto D. Luzon Jr. <edluzonjr at gmail.com>
wrote:

> Hi All,
>
> I found the solution. It is already implemented in pytest but the usage
> only exists in the test and not in the documentation.
> I looked backed on Bruno's commit here and made a similar pytest.ini file
> he created for the test.
> https://bitbucket.org/pytest-dev/pytest/commits/4fb4cb5ae00f
>
> So in my case, this is the perfect solution:
> [pytest]
> python_functions = given and when then but
>
> Many thanks,
> Ernesto D. Luzon Jr.
>
> On Sat, Jan 9, 2016 at 3:57 AM, Ernesto D. Luzon Jr. <edluzonjr at gmail.com>
> wrote:
>
>> Thanks Raphael,
>>
>>     It is almost the thing that I want, however, I would like to be able
>> to pass a tuple/list to pytest_functions.
>>     This way, I think, will allow me to instruct pytest to collect
>> specific set of function prefixes without the need to end all my test
>> functions with a specific suffix.
>>     So instead of python_functions=*_check, something
>> like python_functions=[given, when, then, and, but] would be more desirable.
>>
>>
>> Thanks Dj,
>>
>>      I am also aware of pytest-bdd plugin, however, I think my particular
>> case can not be handled with this plugin.
>>      To demonstrate further, I created this example BDD test written in
>> Jupyter.
>>
>> https://github.com/ldiary/marigoso/blob/master/notes/an_example_of_using_jupyter_for_documenting_and_automating_bdd_style_tests.ipynb
>>
>>      My future plan is to write a pytest plugin that can discover and run
>> tests written like these in Jupyter, but I am just a novice python
>> programmer so I want to start small steps by first writing a script that
>> can copy and paste these into test functions pytest can collect.
>>
>> Many thanks,
>> Ernesto D. Luzon Jr.
>>
>>
>> On Fri, Jan 8, 2016 at 9:49 PM, Dj Gilcrease <digitalxero at gmail.com>
>> wrote:
>>
>>> You may also want to look at
>>>
>>> https://github.com/pytest-dev/pytest-bdd
>>>
>>>
>>>
>>> On Fri, Jan 8, 2016 at 9:47 AM Raphael Pierzina <raphael at hackebrot.de>
>>> wrote:
>>>
>>>> Hi Ernesto,
>>>>
>>>> maybe this is what you are looking for
>>>> https://pytest.org/latest/customize.html#confval-python_functions
>>>>
>>>> hth
>>>> Raphael
>>>>
>>>> On 08 Jan 2016, at 17:30, Ernesto D. Luzon Jr. <edluzonjr at gmail.com>
>>>> wrote:
>>>>
>>>> Hi All,
>>>>
>>>> Is there a way to specify multiple naming conventions for test
>>>> functions?
>>>>
>>>> For example, in my pytest.ini, I would like:
>>>>
>>>> [pytest]
>>>> python_functions=[given, when, then, and, but]
>>>>
>>>>
>>>> Then pytest can discover functions such as:
>>>>
>>>> def given_iam_an_author(): pass
>>>> def and_i_wrote_an_article(): pass
>>>> def when_i_do_this(): pass
>>>> def then_result_is_good(): pass
>>>>
>>>> If this functionality doesn't exist yet, any hint on which pytest code
>>>> I can play with to experiment on this?
>>>>
>>>> Many thanks,
>>>> Ernesto D. Luzon Jr.
>>>> _______________________________________________
>>>> pytest-dev mailing list
>>>> pytest-dev at python.org
>>>> https://mail.python.org/mailman/listinfo/pytest-dev
>>>>
>>>>
>>>> _______________________________________________
>>>> pytest-dev mailing list
>>>> pytest-dev at python.org
>>>> https://mail.python.org/mailman/listinfo/pytest-dev
>>>>
>>>
>>
> _______________________________________________
> pytest-dev mailing list
> pytest-dev at python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20160109/eb16366e/attachment-0001.html>


More information about the pytest-dev mailing list