Skip to content

Context Manager viability #48

@caioaamaral

Description

@caioaamaral

To achieve a sintax similar to ruby's RSpec, it seems to me that the use of Context Managers could be an option:

with describe('a thing'):
    @pytest.fixture
    def foo():
        return 'foo'
    
    with it('does a thing', foo):
        assert foo == 'foo'

A potential issue is the 'assert' statements being evaluated before collection. We could prevent that by wrapping it inside a function that saves it for later evaluation:

with describe('a thing'):
    @pytest.fixture
    def foo():
        return 'foo'
    
    with it('does a thing', foo):
        the_foo = 'foos'
        _assert(foo == the_foo, f'the_foo should be foo, instead got {the_foo}')
    
    with it('does another thing', foo):
        _assert(foo == 'foo')

What would be the restrictions to implement such notation?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions