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

Context Manager viability #48

Open
caioaamaral opened this issue Nov 24, 2024 · 0 comments
Open

Context Manager viability #48

caioaamaral opened this issue Nov 24, 2024 · 0 comments

Comments

@caioaamaral
Copy link

caioaamaral commented Nov 24, 2024

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?

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

1 participant