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

allure-python incompatibility with pytest-asyncio-cooperative #26

Open
rhyspang opened this issue Jul 7, 2022 · 1 comment
Open

allure-python incompatibility with pytest-asyncio-cooperative #26

rhyspang opened this issue Jul 7, 2022 · 1 comment

Comments

@rhyspang
Copy link

rhyspang commented Jul 7, 2022

@allure.feature('page')
class TestPage(object):
    @allure.story('story1')
    @pytest.mark.asyncio_cooperative
    async def test_01(self):
        with allure.step("execute test_02"):
            # await asyncio.sleep(1)
            print("test_01")

allure-python incompatibility with pytest-asyncio-cooperative. Test cases are displayed in the report. but no execution details are shown
No information about test execution is available.

image

@delatrie
Copy link

This is because pytest-asyncio-cooperative messes with an expected lifecycle of a test. It calls a test function directly inside its own event loop before allure-pytest even knows that there actually is a test function. So, when the test steps are created allure-pytest cannot relate them to a test result and basically throws them away.

Here is the place, where test function is called by pytest-asyncio-cooperative (through test_wrapper):

tasks[i] = asyncio.create_task(tasks[i])

And only when the test is done pytest_runtest_protocol hook is called here:

item.ihook.pytest_runtest_protocol(item=item, nextitem=None)

And then, deep inside pytest, pytest_runtest_call creates the test result and pytest_runtest_logfinish closes it. Since the steps were already thrown away at this point the test result remains empty.

If we put pytest-asyncio-cooperative away, the test function will be executed between those two hooks making the steps available for allure-pytest. It basically happens here:
https://github.com/pytest-dev/pytest/blob/3af3f569d5394bb1a18426b0d57a04a094800974/src/_pytest/runner.py#L109

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

No branches or pull requests

2 participants