Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for async steps & scenarios #349

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

amadeuszhercog-silvair
Copy link

@amadeuszhercog-silvair amadeuszhercog-silvair commented Mar 12, 2020

Relates to #223

This pull request adds support for asynchronous steps and scenario functions. As i wrote in README.rst user will be able to use async steps and scenarios out of the box like this:

@pytest.mark.asyncio
@scenario('test.feature', 'Launching scenario function')
def test_launching_scenario_function():
    pass

@given("i have async step")
async def async_given():
    pass

@when("i do async step")
async def async_when():
    pass

@then("i should have async step")
async def async_then():
    pass

Explanation about tests

I've put all tests that use asyncio into tests/asyncio. Their structure is following:

  • test_async_given_returns_value.py - tests checking that async given is a fixture or it can shadow other fixture,
  • test_async_scenario_function.py - tests for scenario function,
  • test_async_steps.py - tests for async steps,
  • test_launching_app_in_background.py - (bigger than above ones) test that will launch dummy application based on asyncio in event_loop.create_task and will interact with it by http protocol. It checks that app is still running between steps and it can respond.
  • dummy_app.py - dummy app from previous point + flask app with which is "gateway" between dummy app and tests.

Data flow of tests based on dummy app looks like this:

test function -> flask server -> dummy app -> flask server -> test function

That PR will require dropping Python 2.7 support before. But since Python 2.7 is no longer officially supported anyway I don't think it would be a problem.

@yanlend
Copy link

yanlend commented May 22, 2020

I don't think the test with the app is worth to add all those testing requirements.

Otherwise, I like the PR. I think adding a native support for asyncio is useful!

@DjaPy DjaPy mentioned this pull request May 25, 2020
@bubenkoff bubenkoff requested a review from youtux January 20, 2021 18:24
@mikeoconnor0308
Copy link

Are there any plans to look at getting this merged?

@youtux
Copy link
Contributor

youtux commented Jun 27, 2021

Hi @amadeuszhercog-silvair, please check my comment about trying to use a different approach for this issue.

It would be better to have async code compatibility without being tied to a specific pytest plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants