pytest-describe
pytest-describe copied to clipboard
Context Manager viability
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?