Skip to content

Verify scope for async fixtures #18

Closed

Description

@touilleMan

Only async fixture with default function scope can work with trio.
Currently, an async fixture with another scope (i.e. module, class or session) will be considered as a regular function and end up as a coroutine in the test function.

This is most likely an inconsistent behavior. A much better solution would be to check the scope of the async fixture before test and raise an error if it's not a correct one.

Following discussion in #17, test file test_fixture_scope.py has been removed until this feature is added to avoid core dump in Python 3.5

import pytest


@pytest.mark.parametrize('scope', ['class', 'module', 'session'])
def test_not_allowed_scopes(testdir, scope):

    testdir.makepyfile(
        """
        import pytest

        @pytest.fixture(scope=%r)
        async def fix1():
            return 'fix1'

        @pytest.mark.trio
        async def test_base(fix1):
            pass  # Crash should have occures before arriving here
    """ % scope
    )

    result = testdir.runpytest()

    result.assert_outcomes(error=1)


@pytest.mark.parametrize('scope', ['function'])
def test_allowed_scopes(testdir, scope):

    testdir.makepyfile(
        """
        import pytest

        @pytest.fixture(scope=%r)
        async def fix1():
            return 'fix1'

        @pytest.mark.trio
        async def test_base(fix1):
            assert fix1 == 'fix1'
    """ % scope
    )

    result = testdir.runpytest()

    result.assert_outcomes(passed=1)

Activity

  1. added 5 commits that reference this issue on Jul 24, 2018
    e2a7e4a
    29be010
    2036d76
    e798215
    eb42b8a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions