pytest-bdd icon indicating copy to clipboard operation
pytest-bdd copied to clipboard

Move the step evaluation into a hook

Open vodik opened this issue 8 years ago • 9 comments
trafficstars

Putting this up to get some feedback and see how receptive people are of the idea before I spend much more time on polishing this.

I'm currently using this library to try and bring this style of testing to our regression, but lots of our code is heavily built around asyncio.

I want to have control over how steps are evaluated, so I can automatically jump in when there's a coroutine and evaluate the step automatically in the current event loop. I'm currently using something like this to demo pytest-bdd internally:

@pytest.hookimpl
def pytest_bdd_call_step(request, feature, scenario, step, step_func, step_func_args):
    if not inspect.iscoroutinefunction(step_func):
        return

    loop = asyncio.get_event_loop()
    loop.run_until_complete(step_func(**step_func_args))
    return True

I don't expect this merged as is, as its is still missing unit tests, documentation, and some quality of life stuff to suppress pluggy from the traceback should a step fail.

Also not sure if you guys want to keep the before and after call hooks too, then, since technically they're now equivalent to having a hook wrapper around this new hook.


This change is Reviewable

vodik avatar Jul 18 '17 15:07 vodik

Is it possible to integrate this feature in the next release?

anxuae avatar Dec 18 '17 16:12 anxuae

Reviewed 3 of 3 files at r1. Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

ggens avatar Dec 21 '17 10:12 ggens

work very well for me . good job.


Review status: :shipit: all files reviewed at latest revision, all discussions resolved, all commit checks successful.


Comments from Reviewable

ggens avatar Dec 21 '17 10:12 ggens

Okay, if that's the case, do you guys want to merge it in its current state? Is there documentation you might want me to update? Should I mark the before/after hooks as deprecated?

vodik avatar Dec 25 '17 23:12 vodik

Any chance we can get something like this in for the next release?

vodik avatar Apr 04 '18 16:04 vodik

I would also be interested in finding out the status for this PR. @bubenkoff and @olegpidsadnyi in your opinion, what would be the remaining steps to finish this pull request?

Victor-Savu avatar May 20 '18 07:05 Victor-Savu

Any idea when/if this will get merged?

pjz avatar Aug 09 '19 15:08 pjz

FWIW, I rebased this on master and used it with some asyncio steps. It seemed to break on example tables, however, making all calls with the literal <fieldname> value instead of one of the values in the column.

pjz avatar Aug 13 '19 18:08 pjz

@bubenkoff, @youtux, @olegpidsadnyi, It seems that the only thing to merge this improvement is just to document the hook. Would it be merged if I complete that documentation?

jruizaranguren avatar Dec 28 '22 12:12 jruizaranguren