Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Context(dict):
- """
- Verb in class name as instruction to usage
- """
- def __getattr__(self, item):
- try:
- return self[item]
- except KeyError:
- raise AttributeError(
- '"{}" does not have "{}" attribute.'.format(self.__class__.__name__, item),
- )
- def __setattr__(self, key, value):
- self[key] = value
- def __delattr__(self, item):
- try:
- del self[item]
- except KeyError:
- raise AttributeError(
- '"{}" does not have "{}" attribute.'.format(self.__class__.__name__, item),
- )
- class Base:
- _ctx = None
- @property
- def ctx(self):
- if self._ctx is None:
- self._ctx = Context()
- return self._ctx
- @pytest.fixture(scope='function', autouse=True)
- def setup(self):
- yield
- allure.attach(name='context',
- body=json.dumps(self._ctx, indent=4),
- attachment_type=allure.attachment_type.TEXT)
- class Test(Base):
- def test(self):
- self.ctx.local_var = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement