5
Ben bağlam yöneticisi ile (birim ile) birim sınama kodu doğru yolu anlamaya çalışıyorum. İşte Içerik yöneticisi için Unittest AttributeError ile başarısız: __exit__
class resources():
def __init__(self):
self.data = 'at-init'
def __enter__(self):
self.data = 'at-enter'
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.data = 'at-exit'
benim unittest kodudur: Burada
benim örnek kod
import unittest
import ctxmgr
class TestResources(unittest.TestCase):
def setUp(self):
pass
def test_ctxmgr(self):
with ctxmgr.resources as r:
self.assertEqual(r.data, 'at-enter')
örnek kod iyi çalışır ancak unittest kod yukarıdaki başarısız olur,
======================================================================
ERROR: test_ctxmgr (__main__.TestResources)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_ctxmgr.py", line 12, in test_ctxmgr
with ctxmgr.resources as r:
AttributeError: __exit__
----------------------------------------------------------------------
Ran 1 test in 0.003s
FAILED (errors=1)
Bu hatayı neden oluyor? Neyi kaçırıyorum?
teşekkürler! bu aptalca bir hata –