Enviroment
- Python 3.6.3
- Киви мастер
- ОС: Linux Mint 18.2 (на основе Ubuntu 16.04 LTS)
код
Привет, я пишу юнит тест kivy.animation
. Когда я запустил код ниже
import unittest
from time import time, sleep
from kivy.animation import Animation
from kivy.uix.widget import Widget
from kivy.clock import Clock
class AnimationTestCase(unittest.TestCase):
SLEEP_DURATION = .3
TIMES = 2
def sleep(self, t):
start = time()
while time() < start + t:
sleep(.01)
Clock.tick()
def test_animation(self):
for index in range(self.TIMES):
print('----------------------------------')
with self.subTest(index=index):
w = Widget()
a = Animation(x=100, d=.2)
print('a:', a)
a.start(w)
self.sleep(self.SLEEP_DURATION)
print('instances_:', Animation._instances)
self.assertEqual(len(Animation._instances), 0)
вывод
----------------------------------
a: <kivy.animation.Animation object at 0x7f0afb31c660>
instances_: set()
----------------------------------
a: <kivy.animation.Animation object at 0x7f0afc20b180>
instances_: {<kivy.animation.Animation object at 0x7f0afc20b250>, <kivy.animation.Animation object at 0x7f0afb31c660>}
======================================================================
FAIL: test_animation (kivy.tests.test_animations.AnimationTestCase) (index=1)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/firefox/kivy/kivy/tests/test_animations.py", line 34, in test_animation
self.assertEqual(len(Animation._instances), 0)
AssertionError: 2 != 0
----------------------------------------------------------------------
Ran 1 test in 0.822s
FAILED (failures=1)
Любой из
- Увеличить SLEEP_DURATION (например,
SLEEP_DURATION = 2
) или
TIMES = 1
исправит эту ошибку.
Это правильное поведение или ошибка?