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

Session-scoped redisdb #590

Open
Seluj78 opened this issue Jan 5, 2024 · 1 comment
Open

Session-scoped redisdb #590

Seluj78 opened this issue Jan 5, 2024 · 1 comment

Comments

@Seluj78
Copy link

Seluj78 commented Jan 5, 2024

I would like to be able to ask pytest-redis to setup a redis instance once per session so I can easily distribute it why pytest-xdist.

Why ? Well it works perfectly right now, but it's hella slow

@pytest.fixture(scope="function")
def app(redisdb):
    application = create_app(redis_instance=redisdb)
    application.testing = True
    return application


@pytest.fixture(scope="function")
def redis_client(app) -> StrictRedis:
    return app.redis


@pytest.fixture(scope="function")
def client(app):
    with app.test_client() as testing_client:
        with app.app_context():
            yield testing_client

Since redisdb is a function-scoped fixture, I have to scope all my other fixtures using app or client as function which really slows down my tests.

I don't want my xdist workers to share anything, on the contrary. I just want the same redis instance for the whole session, for the sake of efficiency and speed (takes about 8 minutes to run 900 tests on github actions with 2 workers, and 2 minutes on 12 workers on my laptop)

@shaeselix
Copy link

+1. If there are any good workarounds to get "module" or "session" scopes, please let us know

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