GithubHelp home page GithubHelp logo

Comments (4)

ImXron avatar ImXron commented on July 20, 2024

Hey @vij-m2. I haven't tested this plugin with asyncio, but it should run your setup / teardown for each loop. So if you have a session scoped fixture that sets up your event loop, it should execute at the start of each loop. Let me know if I'm understanding you correctly. Feel free to post a small, but complete code example for us to work with. You can see and run a small example here.

Just in case that link above doesn't work, this is the code I just ran to test it out:

import pytest


@pytest.fixture(scope="session")
def my_session_fixture():
    print("Session fixture setup.")
    yield
    print("Session fixture teardown.")


@pytest.fixture(scope="function")
def my_function_fixture():
    print("Function fixture setup.")
    yield
    print("Function fixture teardown.")


@pytest.mark.usefixtures("my_session_fixture", "my_function_fixture")
def test_1():
    print("Test case number 1.")
    assert 1


@pytest.mark.usefixtures("my_session_fixture", "my_function_fixture")
def test_2():
    print("Test case number 2.")
    assert 1

Output:

$ pytest --seconds 5 --delay 3 -s -v
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /opt/virtualenvs/python3/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/pytest-stress-10
plugins: stress-1.0.1
collected 2 items                                                              


=================================== Loop # 1 ===================================

test_test.py::test_1 Session fixture setup.
Function fixture setup.
Test case number 1.
PASSEDFunction fixture teardown.

test_test.py::test_2 Function fixture setup.
Test case number 2.
PASSEDFunction fixture teardown.
Session fixture teardown.


=================================== Loop # 2 ===================================

test_test.py::test_1 Session fixture setup.
Function fixture setup.
Test case number 1.
PASSEDFunction fixture teardown.

test_test.py::test_2 Function fixture setup.
Test case number 2.
PASSEDFunction fixture teardown.
Session fixture teardown.


=================================== Loop # 3 ===================================

test_test.py::test_1 Session fixture setup.
Function fixture setup.
Test case number 1.
PASSEDFunction fixture teardown.

test_test.py::test_2 Function fixture setup.
Test case number 2.
PASSEDFunction fixture teardown.
Session fixture teardown.


============================== 6 passed in 6.11s ===============================

Thanks!

from pytest-stress.

vij-m2 avatar vij-m2 commented on July 20, 2024

Hi ImXron, thanks for your response.

Prerequisite: pip install asyncio
Here is the example:

import pytest
pytestmark = [pytest.mark.asyncio]

async def test_a():
    assert True

pytest --seconds 2 <test_path/test_file>
Output is too long. Only the first iteration passes.

from pytest-stress.

ImXron avatar ImXron commented on July 20, 2024

Ah I see. I'm getting the same error as you now.

Deps:

python = "^3.8"
pytest-stress = "^1.0.1"
pytest = "^6.2.4"
pytest-asyncio = "^0.15.1"

This seems related to #4. There's clearly some state that's getting wiped after each session (loop). This plugin basically copies what Pytest is doing for the pytest_runtestloop hook, but throws it in a loop.

I don't have enough knowledge about Pytest's internals. I'll reach out to the Pytest community and see if someone is willing to take a look.

from pytest-stress.

vij-m2 avatar vij-m2 commented on July 20, 2024

Yes, pytest-asyncio is creating event loop only once in the first iteration. It gets closed and doesn't get recreated.
Hope someone from pytest or pytest_asyncio can look into it. Thanks.

from pytest-stress.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.