Advertisement
Guest User

Untitled

a guest
Jun 6th, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. class Context(dict):
  2.     """
  3.    Verb in class name as instruction to usage
  4.    """
  5.  
  6.     def __getattr__(self, item):
  7.         try:
  8.             return self[item]
  9.         except KeyError:
  10.             raise AttributeError(
  11.                 '"{}" does not have "{}" attribute.'.format(self.__class__.__name__, item),
  12.             )
  13.  
  14.     def __setattr__(self, key, value):
  15.         self[key] = value
  16.  
  17.     def __delattr__(self, item):
  18.         try:
  19.             del self[item]
  20.         except KeyError:
  21.             raise AttributeError(
  22.                 '"{}" does not have "{}" attribute.'.format(self.__class__.__name__, item),
  23.             )
  24.  
  25.  
  26. class Base:
  27.    
  28.     _ctx = None
  29.    
  30.     @property
  31.     def ctx(self):
  32.         if self._ctx is None:
  33.             self._ctx = Context()
  34.         return self._ctx
  35.    
  36.     @pytest.fixture(scope='function', autouse=True)
  37.     def setup(self):
  38.         yield
  39.         allure.attach(name='context',
  40.                       body=json.dumps(self._ctx, indent=4),
  41.                       attachment_type=allure.attachment_type.TEXT)
  42.  
  43.  
  44. class Test(Base):
  45.    
  46.     def test(self):
  47.         self.ctx.local_var = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement